diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d19b5cd7492..b9368f7492f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -132,6 +132,14 @@ Also, please bear the following coding guidelines in mind: expansions will be unexpectedly performed, which becomes a vulnerability. In the latter case, checks by shellcheck and shfmt will not be performed inside `'...'`. Also, `_comp_compgen_split` is `IFS`-safe. + + Avoid using `_comp_compgen -- -G "pattern"` to generate completions. The + result is not filtered by the current word `cur` due to the Bash design of + `compgen`. Also, this cannot be used to generate filenames with a specified + extension because the `-G` specification only generates the matching + filepaths in the current directory. It does not look into subdirectories + even when `$cur` implies completion in a subdirectory. One can instead use + `_comp_compgen -- -f -X '!pattern'`. - When completing available options, offer only the most descriptive ones as completion results if there are multiple options that do the diff --git a/completions/feh b/completions/feh index d9550519070..57a23c4bf83 100644 --- a/completions/feh +++ b/completions/feh @@ -29,13 +29,13 @@ _comp_cmd_feh() fi local font_path # font_path="$(imlib2-config --prefix 2>/dev/null)/share/imlib2/data/fonts" - # _comp_compgen -C "$font_path" -- -f -X "!*.@([tT][tT][fF])" -S / + # _comp_compgen -C "$font_path" -- -f -X "!*.[tT][tT][fF]" -S / for ((i = ${#words[@]} - 2; i > 0; i--)); do if [[ ${words[i]} == -@(C|-fontpath) ]]; then font_path="${words[i + 1]}" if [[ -d $font_path ]]; then _comp_compgen -aC "$font_path" -- \ - -f -X "!*.@([tT][tT][fF])" -S / + -f -X "!*.[tT][tT][fF]" -S / fi fi done diff --git a/completions/mdtool b/completions/mdtool index cd179e5f436..22a409e5985 100644 --- a/completions/mdtool +++ b/completions/mdtool @@ -21,10 +21,10 @@ _comp_cmd_mdtool() #if [[ "$prev" == *: ]]; then # case $prev in # @(--p:|--project:)) - # _comp_compgen -- -f -G "*.mdp" + # _comp_compgen -- -f -X '!*.mdp' # ;; # @(--f:|--buildfile:)) - # _comp_compgen -- -f -G "*.mdp" -G "*.mds" + # _comp_compgen -- -f -X '!*.md[ps]' # ;; # esac #fi @@ -32,7 +32,7 @@ _comp_cmd_mdtool() ;; "generate-makefiles") compopt -o filenames - _comp_compgen -- -o filenames -G"*.mds" + _comp_compgen -- -o filenames -f -X '!*.mds' if [[ $prev == *mds ]]; then _comp_compgen -- -W '--simple-makefiles --s --d:' fi diff --git a/completions/rcs b/completions/rcs index aab018e2473..bbf9c6b763d 100644 --- a/completions/rcs +++ b/completions/rcs @@ -5,7 +5,7 @@ _comp_cmd_rcs() local cur prev words cword comp_args _comp_initialize -- "$@" || return - local file dir i + local file dir file=${cur##*/} dir=${cur%/*} @@ -21,8 +21,11 @@ _comp_cmd_rcs() COMPREPLY[i]=$dir$file done - _comp_compgen -aR -- -G "$dir/$file*,v" + local files + _comp_expand_glob files '"$dir/$file"*,v' && + _comp_compgen -aR -- -W '"${files[@]}"' + local i for i in ${!COMPREPLY[*]}; do COMPREPLY[i]=${COMPREPLY[i]%,v} done diff --git a/completions/upgradepkg b/completions/upgradepkg index f359e9add19..0012f6282c3 100644 --- a/completions/upgradepkg +++ b/completions/upgradepkg @@ -15,7 +15,7 @@ _comp_cmd_upgradepkg() cur="${cur#*%}" local nofiles="" compopt -o filenames - _comp_compgen -- -P "$prev%" -f -X "!*.@(t[bgxl]z)" || nofiles=set + _comp_compgen -- -P "$prev%" -f -X "!*.t[bgxl]z" || nofiles=set _comp_compgen -a -- -P "$prev%" -S '/' -d [[ $nofiles ]] && compopt -o nospace return diff --git a/completions/valgrind b/completions/valgrind index 7043aa32fdb..12782922572 100644 --- a/completions/valgrind +++ b/completions/valgrind @@ -7,7 +7,7 @@ _comp_cmd_valgrind() local i for ((i = 1; i <= cword; i++)); do - if [[ ${words[i]} != @([-=])* ]]; then + if [[ ${words[i]} != [-=]* ]]; then _comp_command_offset $i return fi diff --git a/test/runLint b/test/runLint index 550995de147..d011736b18f 100755 --- a/test/runLint +++ b/test/runLint @@ -52,6 +52,9 @@ gitgrep '(?