Skip to content

Commit

Permalink
Fix: 'sel str*' works, but 'desel str*' doesn't
Browse files Browse the repository at this point in the history
  • Loading branch information
leo-arch committed Dec 6, 2024
1 parent 44b5482 commit b5c6af6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/checks.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ check_glob_char(const char *str, const int gflag)
{
if (!str || !*str)
return 0;

return strpbrk(str, (gflag == GLOB_ONLY)
? GLOB_CHARS : GLOB_REGEX_CHARS) ? 1 : 0;
}
Expand Down
23 changes: 12 additions & 11 deletions src/selection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1106,22 +1106,23 @@ static int
deselect_from_args(char **args)
{
char **ds = xnmalloc(args_n + 1, sizeof(char *));
size_t j, k = 0;
size_t i, j = 0;

for (j = 1; j <= args_n; j++) {
char *pp = normalize_path(args[j], strlen(args[j]));
if (!pp)
for (i = 1; i <= args_n; i++) {
char *ptr = normalize_path(args[i], strlen(args[i]));
if (!ptr)
continue;
ds[k] = savestring(pp, strlen(pp));
k++;
free(pp);

ds[j] = savestring(ptr, strlen(ptr));
j++;

free(ptr);
}
ds[k] = (char *)NULL;

if (desel_entries(ds, args_n, 0) == FUNC_FAILURE)
return FUNC_FAILURE;
ds[j] = (char *)NULL;

return FUNC_SUCCESS;
return (desel_entries(ds, j, 0) == FUNC_FAILURE
? FUNC_FAILURE : FUNC_SUCCESS);
}

/* Desel screen: take user input and return an array of input substrings,
Expand Down
18 changes: 13 additions & 5 deletions src/strings.c
Original file line number Diff line number Diff line change
Expand Up @@ -2611,13 +2611,21 @@ glob_expand(char **cmd)
if (!cmd || !cmd[0] || !*cmd[0])
return 0;

/* Do not expand if command is deselect, sel or untrash, just to
* allow the use of "*" for desel and untrash ("ds *" and "u *"),
* and to let the sel function handle glob patterns itself. */
/* In case of 'desel', allow glob expansion onyl if the first parameter
* is not "*", in which the deselect function itself takes care of
* deselecting all files. */
if (sel_n > 0 && cmd[1] && *cmd[1]
&& (strcmp(cmd[0], "ds") == 0 || strcmp(cmd[0], "desel") == 0)) {
if (*cmd[1] == '*' && !cmd[1][1])
return 0;
return (check_glob_char(cmd[1], GLOB_REGEX));
}

if (strcmp(cmd[0], "s") != 0 && strcmp(cmd[0], "sel") != 0
/* Do not expand if command is sel or untrash, just to allow the use
* of "*" for desel and untrash ("ds *" and "u *"), and to let the
* sel function handle glob patterns itself. */

&& strcmp(cmd[0], "ds") != 0 && strcmp(cmd[0], "desel") != 0
if (strcmp(cmd[0], "s") != 0 && strcmp(cmd[0], "sel") != 0

&& strcmp(cmd[0], "u") != 0 && strcmp(cmd[0], "undel") != 0
&& strcmp(cmd[0], "untrash") != 0
Expand Down

0 comments on commit b5c6af6

Please sign in to comment.