Skip to content

Commit 0cbc6da

Browse files
committed
refactor: use _comp_compgen_help with temp vars
1 parent 1e68c7a commit 0cbc6da

File tree

14 files changed

+37
-36
lines changed

14 files changed

+37
-36
lines changed

completions/bzip2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ _comp_cmd_bzip2()
1818
esac
1919

2020
if [[ $cur == -* ]]; then
21-
local helpopts=$(_parse_help "$1")
22-
COMPREPLY=($(compgen -W "${helpopts//#/} -2 -3 -4 -5 -6 -7 -8 -9" \
23-
-- "$cur"))
21+
local helpopts
22+
_comp_compgen -Rv helpopts help
23+
_comp_compgen -- -W '${helpopts[*]//#/} -{2..9}'
2424
return
2525
fi
2626

completions/complete

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ _comp_cmd_complete()
3737
esac
3838

3939
if [[ $cur == -* ]]; then
40-
local -a opts=($(compgen -W '$(_parse_usage help "-s $1")' -- "$cur"))
40+
local -a opts
41+
_comp_compgen -v opts usage -c help -s "$1"
4142
# -F, -C do not work the expected way with compgen
4243
[[ $1 != *compgen ]] || opts=("${opts[@]//-[FC]/}")
4344
_comp_compgen -- -W '"${opts[@]}"' -X ''

completions/declare

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ _comp_cmd_declare()
77

88
if [[ $cur == [-+]* ]]; then
99
local opts
10-
opts=($(_parse_usage help "-s $1"))
10+
_comp_compgen -Rv opts usage -c help -s "$1"
1111
# Most options also have a '+' form.
1212
# We'll exclude the ones that don't with compgen.
1313
opts+=(${opts[*]/-/+})

completions/gnokii

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,20 +221,21 @@ _comp_cmd_gnokii()
221221
esac
222222
fi
223223

224-
local all_cmd="$(_parse_help "$1" "--help all")"
224+
local all_cmd
225+
_comp_compgen -Rv all_cmd help -- --help all
225226

226227
# these 2 below are allowed in combination with others
227228
local main_cmd
228-
_comp_split -l main_cmd "$(command sed -e '/--config/d;/--phone/d' -e \
229-
's/[][\(){}|^$*+?.]/\\&/g' <<<"$all_cmd")"
229+
_comp_split -l main_cmd "$(printf '%s\n' "${all_cmd[@]}" |
230+
command sed -e '/--config/d;/--phone/d;s/[][\(){}|^$*+?.]/\\&/g')"
230231
# don't provide main command completions if one is
231232
# already on the command line
232233
local IFS='|'
233234
local regex_main_cmd="(${main_cmd[*]})($|[^_[:alnum:]])"
234235
IFS=$' \t\n'
235236
[[ $COMP_LINE =~ $regex_main_cmd ]] && return
236237

237-
_comp_compgen -- -W "$all_cmd"
238+
_comp_compgen -- -W '"${all_cmd[@]}"'
238239
} &&
239240
complete -F _comp_cmd_gnokii gnokii
240241

completions/id

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ _comp_cmd_id()
66
_comp_initialize -- "$@" || return
77

88
if [[ $cur == -* ]]; then
9-
local opts=$(_parse_help "$1")
10-
[[ $opts ]] || opts="-G -g -u" # POSIX fallback
11-
_comp_compgen -- -W "$opts"
9+
_comp_compgen_help ||
10+
_comp_compgen -- -W '-G -g -u' # POSIX fallback
1211
else
1312
COMPREPLY=($(compgen -u "$cur"))
1413
fi

completions/mktemp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ _comp_cmd_mktemp()
2020
[[ $was_split ]] && return
2121

2222
if [[ $cur == -* ]]; then
23-
local opts=$(_parse_help "$1")
24-
[[ $opts ]] || opts="-d -u -q -p -t" # non-GNU fallback
25-
_comp_compgen -- -W "$opts"
23+
_comp_compgen_help ||
24+
_comp_compgen -- -W '-d -u -q -p -t' # non-GNU fallback
2625
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
2726
fi
2827
} &&

completions/mysql

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,8 @@ _comp_cmd_mysql()
7878

7979
case $cur in
8080
--*)
81-
local help=$(_parse_help "$1")
82-
help+=" --skip-comments --skip-ssl"
83-
84-
_comp_compgen -- -W "$help"
81+
_comp_compgen_help
82+
_comp_compgen -a -- -W '--skip-comments --skip-ssl'
8583
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
8684
return
8785
;;

completions/openssl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ _comp_cmd_openssl()
4141
local cur prev words cword comp_args
4242
_comp_initialize -- "$@" || return
4343

44-
local commands command options formats
44+
local commands command formats
4545

4646
commands='asn1parse ca ciphers crl crl2pkcs7 dgst dh dhparam dsa dsaparam
4747
ec ecparam enc engine errstr gendh gendsa genrsa nseq ocsp passwd
@@ -117,11 +117,13 @@ _comp_cmd_openssl()
117117

118118
if [[ $cur == -* ]]; then
119119
# possible options for the command
120-
options=$(_parse_help "$1" "$command -help" 2>/dev/null)
120+
_comp_compgen_help -- "$command" -help
121121
case $command in
122-
dgst | req | x509) options+=" $(_openssl_digests "$1")" ;;
122+
dgst | req | x509)
123+
local options=$(_openssl_digests "$1")
124+
_comp_compgen -a -- -W '$options'
125+
;;
123126
esac
124-
_comp_compgen -- -W "$options"
125127
else
126128
if [[ $command == speed ]]; then
127129
COMPREPLY=($(compgen -W 'md2 mdc2 md5 hmac sha1 rmd160

completions/pwdx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ _comp_cmd_pwdx()
1212
esac
1313

1414
if [[ $cur == -* ]]; then
15-
local help=$(_parse_help "$1")
16-
[[ $help ]] || help=-V
17-
_comp_compgen -- -W '$help'
15+
_comp_compgen_help ||
16+
_comp_compgen -- -W '-V'
1817
else
1918
_pids
2019
fi

completions/rdesktop

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ _comp_cmd_rdesktop()
4646
esac
4747

4848
if [[ $cur == -* ]]; then
49-
local opts=($(_parse_help "$1"))
49+
local -a opts
50+
_comp_compgen -Rv opts help
5051
((${#opts[@]})) &&
5152
_comp_compgen -- -W '"${opts[@]%:}"'
5253
else

0 commit comments

Comments
 (0)