Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use _comp_compgen for COMPREPLY=($(compgen ...)) #955

Merged
merged 15 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,7 @@ _comp_compgen()

local _result
_result=$(
IFS=$_ifs
compgen "$@" ${_cur:+-- "$_cur"}
IFS=$_ifs compgen "$@" ${_cur:+-- "$_cur"}
) || {
local _status=$?
if [[ $_append ]]; then
Expand Down
24 changes: 8 additions & 16 deletions completions/7z
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ _comp_cmd_7z()
_comp_initialize -n = -- "$@" || return

if ((cword == 1)); then
COMPREPLY=($(compgen -W 'a b d e h i l rn t u x' -- "$cur"))
_comp_compgen -- -W 'a b d e h i l rn t u x'
return
fi

Expand All @@ -15,7 +15,7 @@ _comp_cmd_7z()

case $cur in
-ao*)
COMPREPLY=($(compgen -P"${cur:0:3}" -W 'a s t u' -- "${cur:3}"))
_comp_compgen -c "${cur:3}" -- -P"${cur:0:3}" -W 'a s t u'
return
;;
-?(a)[ix]*)
Expand All @@ -29,35 +29,27 @@ _comp_cmd_7z()
COMPREPLY=($(compgen -P"$opt" -W '@ ! r@ r-@ r0@ r! r-! r0!' \
-- "$cur"))
elif [[ $cur == ?(r@(-|0|))@* ]]; then
local IFS=$' \t\n' reset=$(shopt -po noglob)
set -o noglob
COMPREPLY=($(compgen -P"${opt}${cur%%@*}@" -f -- "${cur#*@}"))
$reset
_comp_compgen -c "${cur#*@}" -- -P"${opt}${cur%%@*}@" -f
compopt -o filenames
fi
return
;;
-mhe=* | -mhc=* | -ms=* | -mt=*)
COMPREPLY=($(compgen -W 'on off' -- "${cur#*=}"))
_comp_compgen -c "${cur#*=}" -- -W 'on off'
return
;;
-mx=*)
COMPREPLY=($(compgen -W '0 1 3 5 7 9' -- "${cur#*=}"))
_comp_compgen -c "${cur#*=}" -- -W '0 1 3 5 7 9'
return
;;
-o* | -w?*)
local reset=$(shopt -po noglob)
set -o noglob
compopt -o filenames
local IFS=$'\n'
COMPREPLY=($(compgen -d -P"${cur:0:2}" -S/ -- "${cur:2}"))
_comp_unlocal IFS
$reset
_comp_compgen -c "${cur:2}" -- -d -P"${cur:0:2}" -S/
compopt -o nospace
return
;;
-r?*)
COMPREPLY=($(compgen -P"${cur:0:2}" -W '- 0' -- "${cur:2}"))
_comp_compgen -c "${cur:2}" -- -P"${cur:0:2}" -W '- 0'
return
;;
-scs*)
Expand All @@ -66,7 +58,7 @@ _comp_cmd_7z()
return
;;
-ssc?*)
COMPREPLY=($(compgen -P"${cur:0:4}" -W '-' -- "${cur:4}"))
_comp_compgen -c "${cur:4}" -- -P"${cur:0:4}" -W '-'
return
;;
-t*)
Expand Down
4 changes: 2 additions & 2 deletions completions/_adb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ _comp_cmd_adb()
tmp+=(devices connect disconnect sideload)
fi
((${#tmp[@]})) &&
COMPREPLY=($(compgen -W '"${tmp[@]}"' -- "$cur"))
_comp_compgen -- -W '"${tmp[@]}"'
return
fi

Expand All @@ -62,7 +62,7 @@ _comp_cmd_adb()
_parse_help -)' -- "$cur"))
;;
reboot)
COMPREPLY=($(compgen -W 'bootloader recovery' -- "$cur"))
_comp_compgen -- -W 'bootloader recovery'
;;
esac
} &&
Expand Down
4 changes: 2 additions & 2 deletions completions/_cal
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ _comp_cmd_cal()
case $prev in
-m)
if [[ $OSTYPE == *bsd* ]]; then
COMPREPLY=($(compgen -W '{1..12}' -- "$cur"))
_comp_compgen -- -W '{1..12}'
return
fi
;;
Expand All @@ -32,7 +32,7 @@ _comp_cmd_cal()

local args
_count_args
((args == 1)) && COMPREPLY=($(compgen -W '{1..12}' -- "$cur"))
((args == 1)) && _comp_compgen -- -W '{1..12}'
} &&
complete -F _comp_cmd_cal cal ncal

Expand Down
2 changes: 1 addition & 1 deletion completions/_dmesg
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ _comp_cmd_dmesg()
return
;;
-l | --level | -n | --console-level)
COMPREPLY=($(compgen -W '{1..8}' -- "$cur"))
_comp_compgen -- -W '{1..8}'
return
;;
esac
Expand Down
2 changes: 1 addition & 1 deletion completions/_eject
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ _comp_cmd_eject()
return
;;
-a | --auto | -i | --manualeject)
COMPREPLY=($(compgen -W 'on off' -- "$cur"))
_comp_compgen -- -W 'on off'
return
;;
esac
Expand Down
4 changes: 2 additions & 2 deletions completions/_ionice
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ _comp_cmd_ionice()

case $prev in
-c)
COMPREPLY=($(compgen -W '{0..3}' -- "$cur"))
_comp_compgen -- -W '{0..3}'
return
;;
-n)
COMPREPLY=($(compgen -W '{0..7}' -- "$cur"))
_comp_compgen -- -W '{0..7}'
return
;;
-p)
Expand Down
2 changes: 1 addition & 1 deletion completions/_mock
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ _comp_cmd_mock()
return
;;
--enable-plugin | --disable-plugin)
COMPREPLY=($(compgen -W "$plugins" -- "$cur"))
_comp_compgen -- -W "$plugins"
return
;;
esac
Expand Down
2 changes: 1 addition & 1 deletion completions/_modules
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ _comp_cmd_module()
options="$(module help 2>&1 | command grep -E '^[[:space:]]*\+' |
awk '{print $2}' | command sed -e 's/|/ /g' | sort)"

COMPREPLY=($(compgen -W "$options" -- "$cur"))
_comp_compgen -- -W "$options"

elif ((cword == 2)); then
case $prev in
Expand Down
8 changes: 4 additions & 4 deletions completions/_mount.linux
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ _comp_cmd_mount()
return
;;
-p | --pass-fd)
COMPREPLY=($(compgen -W '{0..9}'))
_comp_compgen -R -- -W '{0..9}'
compopt -o nospace
return
;;
Expand Down Expand Up @@ -86,7 +86,7 @@ _comp_cmd_mount()
{,no}user users' -- "$cur"))
case "$fstype" in
adfs | auto)
COMPREPLY+=($(compgen -W '{u,g}id= {own,oth}mask=' -- "$cur"))
_comp_compgen -a -- -W '{u,g}id= {own,oth}mask='
;;&
affs | auto)
COMPREPLY+=($(compgen -W '{u,g}id= set{u,g}id= mode= protect
Expand Down Expand Up @@ -145,7 +145,7 @@ _comp_cmd_mount()
iocharset= utf8' -- "$cur"))
;;&
jffs2 | auto)
COMPREPLY+=($(compgen -W 'compr= rp_size=' -- "$cur"))
_comp_compgen -a -- -W 'compr= rp_size='
;;&
jfs | auto)
COMPREPLY+=($(compgen -W 'iocharset= resize= {,no}integrity
Expand Down Expand Up @@ -175,7 +175,7 @@ _comp_cmd_mount()
{,no}compression debug no_detach' -- "$cur"))
;;&
proc | auto)
COMPREPLY+=($(compgen -W '{u,g}id=' -- "$cur"))
_comp_compgen -a -- -W '{u,g}id='
;;&
reiserfs | auto)
COMPREPLY+=($(compgen -W 'conv hash= {,no_un}hashed_relocation
Expand Down
20 changes: 10 additions & 10 deletions completions/_nmcli
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

_comp_cmd_nmcli__list()
{
COMPREPLY=($(compgen -W '$1' -- "$cur"))
_comp_compgen -- -W '$1'
}

_comp_cmd_nmcli__con_id()
Expand Down Expand Up @@ -41,11 +41,11 @@ _comp_cmd_nmcli()

case $prev in
-m | --mode)
COMPREPLY=($(compgen -W 'tabular multiline' -- "$cur"))
_comp_compgen -- -W 'tabular multiline'
return
;;
-f | --fields)
COMPREPLY=($(compgen -W 'all common' -- "$cur"))
_comp_compgen -- -W 'all common'
return
;;
-e | --escape)
Expand Down Expand Up @@ -79,7 +79,7 @@ _comp_cmd_nmcli()
COMPREPLY=($(compgen -W '--terse --pretty --mode --fields
--escape --version --help' -- "$cur"))
else
COMPREPLY=($(compgen -W "nm con dev" -- "$cur"))
_comp_compgen -- -W "nm con dev"
fi
else
local object=${words[1]}
Expand Down Expand Up @@ -116,7 +116,7 @@ _comp_cmd_nmcli()
con)
case $command in
list)
COMPREPLY=($(compgen -W 'id uuid' -- "$cur"))
_comp_compgen -- -W 'id uuid'
return
;;
up)
Expand All @@ -130,11 +130,11 @@ _comp_cmd_nmcli()
return
;;
down)
COMPREPLY=($(compgen -W 'id uuid' -- "$cur"))
_comp_compgen -- -W 'id uuid'
return
;;
delete)
COMPREPLY=($(compgen -W 'id uuid' -- "$cur"))
_comp_compgen -- -W 'id uuid'
return
;;
esac
Expand All @@ -145,15 +145,15 @@ _comp_cmd_nmcli()
dev)
case $command in
list)
COMPREPLY=($(compgen -W 'iface' -- "$cur"))
_comp_compgen -- -W 'iface'
return
;;
disconnect)
if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W '--nowait --timeout' \
-- "$cur"))
else
COMPREPLY=($(compgen -W 'iface' -- "$cur"))
_comp_compgen -- -W 'iface'
fi
return
;;
Expand Down Expand Up @@ -183,7 +183,7 @@ _comp_cmd_nmcli()
;;
esac

COMPREPLY=($(compgen -W 'list connect' -- "$cur"))
_comp_compgen -- -W 'list connect'
return
;;
esac
Expand Down
2 changes: 1 addition & 1 deletion completions/_rfkill
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ _comp_cmd_rfkill()
_comp_initialize -- "$@" || return

if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W '--version' -- "$cur"))
_comp_compgen -- -W '--version'
else
case $cword in
1)
Expand Down
4 changes: 2 additions & 2 deletions completions/_rtcwake
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ _comp_cmd_rtcwake()
return
;;
--mode | -m)
COMPREPLY=($(compgen -W 'standby mem disk on no off' -- "$cur"))
_comp_compgen -- -W 'standby mem disk on no off'
return
;;
--device | -d)
_comp_expand_glob COMPREPLY '/dev/rtc?*'
((${#COMPREPLY[@]})) &&
COMPREPLY=($(compgen -W '"${COMPREPLY[@]#/dev/}"' -- "$cur"))
_comp_compgen -- -W '"${COMPREPLY[@]#/dev/}"'
return
;;
esac
Expand Down
6 changes: 3 additions & 3 deletions completions/_slackpkg
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ _comp_cmd_slackpkg()
-delall | -checkmd5 | -checkgpg | -checksize | -postinst | -onoff | \
-download_all | -dialog | -batch | -only_new_dotnew | \
-use_includes | -spinning)
COMPREPLY=($(compgen -W 'on off' -- "$cur"))
_comp_compgen -- -W 'on off'
return
;;
-default_answer)
COMPREPLY=($(compgen -W 'yes no' -- "$cur"))
_comp_compgen -- -W 'yes no'
return
;;
-dialog_maxargs | -mirror)
Expand Down Expand Up @@ -98,7 +98,7 @@ _comp_cmd_slackpkg()
;;
update)
# we should complete the same as the next `list` + "gpg"
COMPREPLY=($(compgen -W 'gpg' -- "$cur"))
_comp_compgen -- -W 'gpg'
;&
*)
COMPREPLY+=($(compgen -W 'install reinstall upgrade remove
Expand Down
5 changes: 2 additions & 3 deletions completions/_su
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ _comp_cmd_su()
return
;;
-c | --command | --session-command)
local IFS=$'\n'
compopt -o filenames
COMPREPLY=($(compgen -d -c -- "$cur"))
_comp_compgen -- -d -c
return
;;
esac
Expand All @@ -34,7 +33,7 @@ _comp_cmd_su()
return
fi

COMPREPLY=($(compgen -u -- "$cur"))
_comp_compgen -- -u
} &&
complete -F _comp_cmd_su su

Expand Down
10 changes: 5 additions & 5 deletions completions/_svn
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ _comp_cmd_svn()

if ((cword == 1)); then
if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W '--version' -- "$cur"))
_comp_compgen -- -W '--version'
else
COMPREPLY=($(compgen -W "$commands" -- "$cur"))
_comp_compgen -- -W "$commands"
fi
else

Expand All @@ -39,7 +39,7 @@ _comp_cmd_svn()
;;
--editor-cmd | --diff-cmd | --diff3-cmd)
compopt -o filenames
COMPREPLY=($(compgen -c -- "$cur"))
_comp_compgen -- -c
return
;;
esac
Expand Down Expand Up @@ -194,10 +194,10 @@ _comp_cmd_svn()
esac
options+=" --help --config-dir"

COMPREPLY=($(compgen -W "$options" -- "$cur"))
_comp_compgen -- -W "$options"
else
if [[ $command == @(help|[h?]) ]]; then
COMPREPLY=($(compgen -W "$commands" -- "$cur"))
_comp_compgen -- -W "$commands"
else
_comp_compgen_filedir
fi
Expand Down
Loading