Skip to content

Commit dfb903b

Browse files
committed
fix(invoke-rc.d): fix a bug of generating existing words
In the current implementation, we try to filter out the elements of "${options[@]}" that already appear in "${words[@]}". The strategy is to generate a. "${options[@]}" and b. the intersect of "${words[@]}" and "${options[@]}" in a single list and to pick up only unique elements. However, the current implementation does not correctly generate "b. the intersect". It also contains elements of words that contain any of "${options[@]}" as a substring. This possibly results in generating some words in the command line as options. scop#1564 (comment) In this patch, we rather implement the filtering using `_compgen -X`.
1 parent cc75da2 commit dfb903b

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

completions-core/invoke-rc.d.bash

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,10 @@ _comp_cmd_invoke_rc_d()
1818
if [[ $cword -eq 1 || $prev == --* ]]; then
1919
# generate valid_options
2020
local IFS='|'
21-
local regex_options="${options[*]}"
22-
IFS=$' \t\n'
23-
_comp_compgen_split -- "$(
24-
tr " " "\n" <<<"${words[*]} ${options[*]}" |
25-
command grep -E -e "$regex_options" |
26-
sort | uniq -u
27-
)"
21+
local exclude="@(${words[*]})"
22+
_comp_unlocal IFS
23+
_comp_compgen -- -W '"${options[@]}"' -X "$exclude"
24+
2825
_comp_expand_glob services '"$sysvdir"/!(README*|*.sh|$_comp_backup_glob)' &&
2926
_comp_compgen -a -- -W '"${services[@]#"$sysvdir"/}"'
3027
elif [[ -x $sysvdir/$prev ]]; then

0 commit comments

Comments
 (0)