Skip to content

Commit e06a482

Browse files
authored
Merge pull request #969 from akinomyoga/_parse_help-2
refactor: use `_comp_compgen_{help,usage}` with non-trivial rewriting
2 parents 4d82296 + 37c48d6 commit e06a482

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+154
-155
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
_comp_compgen -- -W 'update upgrade safe-upgrade forget-new clean
9999
autoclean install reinstall remove hold unhold purge markauto

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/chronyc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ _comp_cmd_chronyc()
2929
esac
3030

3131
if [[ $cur == -* ]]; then
32-
COMPREPLY=($(compgen -W '$(_parse_usage "$1") -6' -- "$cur"))
32+
_comp_compgen_usage
33+
_comp_compgen -a -- -W '-6'
3334
return
3435
fi
3536

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/cvs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,9 @@ _comp_cmd_cvs()
408408
;;
409409
esac
410410

411-
COMPREPLY=($(compgen -W '$(_cvs_commands)
412-
$(_parse_help "$1" --help-options) --help --help-commands
413-
--help-options --version' -- "$cur"))
411+
_comp_compgen_help -- --help-options
412+
_comp_compgen -a -- -W '$(_cvs_commands) --help
413+
--help-commands --help-options --version'
414414
;;
415415
esac
416416

completions/dd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ _comp_cmd_dd()
2929
;;
3030
esac
3131

32-
COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur")
33-
$(compgen -W 'bs cbs conv count ibs if iflag obs of oflag
34-
seek skip status' -S '=' -- "$cur"))
32+
_comp_compgen_help
33+
_comp_compgen -a -- -W 'bs cbs conv count ibs if iflag obs of oflag
34+
seek skip status' -S '='
3535
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
3636
} &&
3737
complete -F _comp_cmd_dd dd

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/dsniff

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ _comp_cmd_dsniff()
1717
esac
1818

1919
if [[ $cur == -* ]]; then
20-
COMPREPLY=($(compgen -W '$(_parse_usage "$1") -r -w -p' -- "$cur"))
20+
_comp_compgen_usage
21+
_comp_compgen -a -- -W '-r -w -p'
2122
fi
2223

2324
} &&

completions/ether-wake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ _comp_cmd_ether_wake()
1616
esac
1717

1818
if [[ $cur == -* ]]; then
19-
COMPREPLY=($(compgen -W '$(_parse_help "$1" -u) -V' -- "$cur"))
19+
_comp_compgen_help -- -u
20+
_comp_compgen -a -- -W '-V'
2021
return
2122
fi
2223

0 commit comments

Comments
 (0)