Skip to content

Commit 1286057

Browse files
committed
refactor: use _comp_compgen_help for _parse_help -
1 parent 0cbc6da commit 1286057

File tree

17 files changed

+58
-78
lines changed

17 files changed

+58
-78
lines changed

completions/_adb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55

66
_comp_cmd_adb__command_usage()
77
{
8-
COMPREPLY=($(compgen -W '$("$1" help 2>&1 | \
9-
command sed -e "/^ *\(adb \)\{0,1\} *$2 /!d;s/[]|[]/\n/g" | \
10-
_parse_help -)' -- "$cur"))
8+
_comp_compgen_help - <<<"$("$1" help 2>&1 |
9+
command sed -e "/^ *\(adb \)\{0,1\} *$2 /!d;s/[]|[]/\n/g")"
1110
}
1211

1312
_comp_cmd_adb()
@@ -57,9 +56,8 @@ _comp_cmd_adb()
5756
_comp_compgen -a filedir
5857
;;
5958
forward)
60-
COMPREPLY=($(compgen -W \
61-
'$("$1" help 2>&1 | command sed -ne "s/^ *adb *forward *-/-/p" | \
62-
_parse_help -)' -- "$cur"))
59+
_comp_compgen_help - <<<"$("$1" help 2>&1 |
60+
command sed -ne "s/^ *adb *forward *-/-/p")"
6361
;;
6462
reboot)
6563
_comp_compgen -- -W 'bootloader recovery'

completions/aptitude

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,19 @@ _comp_cmd_aptitude()
6060
esac
6161

6262
if [[ $cur == -* ]]; then
63-
local opts=" $("$1" --help 2>&1 | command sed -e \
64-
's/--with(out)-recommends/--without-recommends\n--with-recommends/' |
65-
_parse_help - | tr '\n' ' ') "
63+
_comp_compgen -R help - <<<"$("$1" --help 2>&1 | command sed -e \
64+
's/--with(out)-recommends/--without-recommends\n--with-recommends/')"
65+
((${#COMPREPLY[@]})) || return 0
6666

6767
# Exclude some mutually exclusive options
68+
local exclude_flags=""
6869
for i in "${words[@]}"; do
69-
[[ $i == -u ]] && opts=${opts/ -i / }
70-
[[ $i == -i ]] && opts=${opts/ -u / }
70+
[[ $i == -u ]] && exclude_flags+=i
71+
[[ $i == -i ]] && exclude_flags+=u
7172
done
7273

7374
# Do known short -> long replacements; at least up to 0.8.12, --help
7475
# outputs mostly only short ones.
75-
COMPREPLY=($opts)
7676
for i in "${!COMPREPLY[@]}"; do
7777
case ${COMPREPLY[i]} in
7878
-h) COMPREPLY[i]=--help ;;
@@ -92,8 +92,8 @@ _comp_cmd_aptitude()
9292
esac
9393
done
9494

95-
((${#COMPREPLY[@]})) &&
96-
_comp_compgen -- -W '"${COMPREPLY[@]}"'
95+
_comp_compgen -- -W '"${COMPREPLY[@]}"' \
96+
${exclude_flags:+-X "-[$exclude_flags]"}
9797
else
9898
COMPREPLY=($(compgen -W 'update upgrade safe-upgrade forget-new
9999
clean autoclean install reinstall remove hold unhold purge markauto

completions/ip

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,14 @@ _comp_cmd_ip()
5555
if [[ ! $has_cmd ]]; then
5656
case $cur in
5757
-*)
58-
local force=""
59-
((cword == 1)) && force=-force
60-
COMPREPLY=($(compgen -W "$force $(
58+
_comp_compgen -a help - <<<"$(
59+
((cword == 1)) && printf '%s\n' -force
6160
{
62-
$1 -c=never help || $1 help
61+
"$1" -c=never help || "$1" help
6362
} 2>&1 | command sed -e \
6463
's/[{|}=]/\n/g' -e \
65-
's/\[\([^]]\{1,\}\)\]/\1/g' |
66-
_parse_help -
67-
)" -- "$cur"))
64+
's/\[\([^]]\{1,\}\)\]/\1/g'
65+
)"
6866
;;
6967
*)
7068
COMPREPLY=($(compgen -W "help $(

completions/iperf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ _comp_cmd_iperf()
8282
done
8383
[[ $filter != cat ]] && filter+=' -e /--client/d -e /--server/d'
8484

85-
COMPREPLY=($(compgen -W \
86-
'$("$1" --help 2>&1 | $filter | _parse_help -)' -- "$cur"))
85+
_comp_compgen_help - <<<"$("$1" --help 2>&1 | $filter)"
8786
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
8887
} &&
8988
complete -F _comp_cmd_iperf iperf iperf3

completions/iptables

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ _comp_cmd_iptables()
3939
;;
4040
*)
4141
if [[ $cur == -* ]]; then
42-
COMPREPLY=($(compgen -W '$("$1" --help 2>&1 |
43-
command sed -e "s/^\[\!\]//" | _parse_help -)' -- "$cur"))
42+
_comp_compgen_help - <<<"$("$1" --help 2>&1 |
43+
command sed -e "s/^\[\!\]//")"
4444
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
4545
fi
4646
;;

completions/ipv6calc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ _comp_cmd_ipv6calc()
3030
[[ $was_split ]] && return
3131

3232
if [[ $cur == -* ]]; then
33-
COMPREPLY=($(compgen -W '$("$1" -h 2>&1 |
34-
command sed -e "s/[][]//g" | _parse_help -)' -- "$cur"))
33+
_comp_compgen_help - <<<"$("$1" -h 2>&1 |
34+
command sed -e "s/[][]//g")"
3535
fi
3636

3737
} &&

completions/jq

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ _comp_cmd_jq()
4444

4545
if [[ $help_output == *--help* ]]; then
4646
# If the output of --help seems complete, use it
47-
COMPREPLY=($(compgen -W \
48-
'$(printf "%s" "$help_output" | _parse_help -)' -- "$cur"))
47+
_comp_compgen_help - <<<"$help_output"
4948
else
5049
# Otherwise, use a hard-coded list of known flags, some of which do
5150
# not appear in the output of --help as of jq 1.6.

completions/makepkg

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ _comp_cmd_makepkg__slackware()
1414
esac
1515

1616
if [[ $cur == -* ]]; then
17-
COMPREPLY=($(compgen -W \
18-
'$("$1" | command sed -e "s/^options://" | _parse_help -)' \
19-
-- "$cur"))
17+
_comp_compgen_help - <<<"$("$1" | command sed -e "s/^options://")"
2018
return
2119
fi
2220

completions/mr

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ _comp_cmd_mr()
1010
help="$(PERLDOC_PAGER=cat PERLDOC=-otext "${1}" help 2>/dev/null)"
1111

1212
commands="$(
13+
# shellcheck disable=SC2030
1314
printf %s "$help" | while read -r _ options cmd _; do
1415
[[ $options != "[options]" ]] || printf "%s\n" "$cmd"
1516
done
@@ -79,12 +80,10 @@ _comp_cmd_mr()
7980
esac
8081

8182
if [[ $cur == -* ]]; then
82-
options="$(printf '%s\n' "$help" | _parse_help -)"
83-
# Remove short options (all have compatible long options).
84-
options="${options//-[a-z]$'\n'/}"
85-
# Remove deprecated options.
86-
options="${options//--path/}"
87-
_comp_compgen -- -W "${options}"
83+
_comp_compgen -Rv options help - <<<"$help"
84+
# -X '-[a-z]': Remove short options (all have compatible long options).
85+
# -X '--path': Remove deprecated options.
86+
_comp_compgen -- -W '"${options[@]}"' -X '@(-[a-z]|--path)'
8887
else
8988
_comp_compgen -- -W "${commands}"
9089
fi

completions/pgrep

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,9 @@ _comp_cmd_pgrep()
4848
esac
4949

5050
if [[ $cur == -* ]]; then
51-
local help=$(_parse_help "$1")
52-
[[ $help ]] || help='$("$1" --usage 2>&1 |
53-
command sed -e "s/\[-signal\]//" -e "s/\[-SIGNAL\]//" |
54-
_parse_usage -)'
55-
_comp_compgen -- -W "$help"
51+
_comp_compgen_help ||
52+
_comp_compgen_usage - <<<"$("$1" --usage 2>&1 |
53+
command sed -e "s/\[-signal\]//" -e "s/\[-SIGNAL\]//")"
5654
[[ $cword -eq 1 && $1 == *pkill ]] && _signals -
5755
return
5856
fi

0 commit comments

Comments
 (0)