File tree 7 files changed +23
-9
lines changed
7 files changed +23
-9
lines changed Original file line number Diff line number Diff line change @@ -132,6 +132,14 @@ Also, please bear the following coding guidelines in mind:
132
132
expansions will be unexpectedly performed, which becomes a vulnerability. In
133
133
the latter case, checks by shellcheck and shfmt will not be performed inside
134
134
` '...' ` . Also, ` _comp_compgen_split ` is ` IFS ` -safe.
135
+
136
+ Avoid using ` _comp_compgen -- -G "pattern" ` to generate completions. The
137
+ result is not filtered by the current word ` cur ` due to the Bash design of
138
+ ` compgen ` . Also, this cannot be used to generate filenames with a specified
139
+ extension because the ` -G ` specification only generates the matching
140
+ filepaths in the current directory. It does not look into subdirectories
141
+ even when ` $cur ` implies completion in a subdirectory. One can instead use
142
+ ` _comp_compgen -- -f -X '!pattern' ` .
135
143
136
144
- When completing available options, offer only the most descriptive
137
145
ones as completion results if there are multiple options that do the
Original file line number Diff line number Diff line change @@ -29,13 +29,13 @@ _comp_cmd_feh()
29
29
fi
30
30
local font_path
31
31
# font_path="$(imlib2-config --prefix 2>/dev/null)/share/imlib2/data/fonts"
32
- # _comp_compgen -C "$font_path" -- -f -X "!*.@( [tT][tT][fF]) " -S /
32
+ # _comp_compgen -C "$font_path" -- -f -X "!*.[tT][tT][fF]" -S /
33
33
for (( i = ${# words[@]} - 2 ; i > 0 ; i-- )) ; do
34
34
if [[ ${words[i]} == -@ (C| -fontpath) ]]; then
35
35
font_path=" ${words[i + 1]} "
36
36
if [[ -d $font_path ]]; then
37
37
_comp_compgen -aC " $font_path " -- \
38
- -f -X " !*.@( [tT][tT][fF]) " -S /
38
+ -f -X " !*.[tT][tT][fF]" -S /
39
39
fi
40
40
fi
41
41
done
Original file line number Diff line number Diff line change @@ -21,18 +21,18 @@ _comp_cmd_mdtool()
21
21
# if [[ "$prev" == *: ]]; then
22
22
# case $prev in
23
23
# @(--p:|--project:))
24
- # _comp_compgen -- -f -G " *.mdp"
24
+ # _comp_compgen -- -f -X '! *.mdp'
25
25
# ;;
26
26
# @(--f:|--buildfile:))
27
- # _comp_compgen -- -f -G "*.mdp" -G "*.mds"
27
+ # _comp_compgen -- -f -X '!*.md[ps]'
28
28
# ;;
29
29
# esac
30
30
# fi
31
31
return
32
32
;;
33
33
" generate-makefiles" )
34
34
compopt -o filenames
35
- _comp_compgen -- -o filenames -G " *.mds"
35
+ _comp_compgen -- -o filenames -f -X ' ! *.mds'
36
36
if [[ $prev == * mds ]]; then
37
37
_comp_compgen -- -W ' --simple-makefiles --s --d:'
38
38
fi
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ _comp_cmd_rcs()
5
5
local cur prev words cword comp_args
6
6
_comp_initialize -- " $@ " || return
7
7
8
- local file dir i
8
+ local file dir
9
9
10
10
file=${cur##*/ }
11
11
dir=${cur%/* }
@@ -21,8 +21,11 @@ _comp_cmd_rcs()
21
21
COMPREPLY[i]=$dir$file
22
22
done
23
23
24
- _comp_compgen -aR -- -G " $dir /$file *,v"
24
+ local files
25
+ _comp_expand_glob files ' "$dir/$file"*,v' &&
26
+ _comp_compgen -aR -- -W ' "${files[@]}"'
25
27
28
+ local i
26
29
for i in ${! COMPREPLY[*]} ; do
27
30
COMPREPLY[i]=${COMPREPLY[i]% ,v}
28
31
done
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ _comp_cmd_upgradepkg()
15
15
cur=" ${cur#*% } "
16
16
local nofiles=" "
17
17
compopt -o filenames
18
- _comp_compgen -- -P " $prev %" -f -X " !*.@( t[bgxl]z) " || nofiles=set
18
+ _comp_compgen -- -P " $prev %" -f -X " !*.t[bgxl]z" || nofiles=set
19
19
_comp_compgen -a -- -P " $prev %" -S ' /' -d
20
20
[[ $nofiles ]] && compopt -o nospace
21
21
return
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ _comp_cmd_valgrind()
7
7
8
8
local i
9
9
for (( i = 1 ; i <= cword; i++ )) ; do
10
- if [[ ${words[i]} != @ ( [-= ]) * ]]; then
10
+ if [[ ${words[i]} != [-= ]* ]]; then
11
11
_comp_command_offset $i
12
12
return
13
13
fi
Original file line number Diff line number Diff line change @@ -52,6 +52,9 @@ gitgrep '(?<!command)'"$cmdstart"'(grep|ls|sed|cd)(\s|$)' \
52
52
gitgrep ' (?<!command)' " $cmdstart " ' awk(\s|$)' \
53
53
' invoke awk through "_comp_awk"'
54
54
55
+ gitgrep ' @\([^()|$]+\)' \
56
+ ' @(...) may not be needed when ... does not contain |.'
57
+
55
58
# ------------------------------------------------------------------------------
56
59
# Bash pitfalls/styles/compatibilities (which are not detected by shellcheck)
57
60
You can’t perform that action at this time.
0 commit comments