Skip to content

Commit

Permalink
refactor: use _comp_compgen_split for -W '$(...)'
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed May 28, 2023
1 parent cb347cb commit 08fba21
Show file tree
Hide file tree
Showing 67 changed files with 223 additions and 255 deletions.
39 changes: 19 additions & 20 deletions bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,7 @@ _comp_variable_assignments()
_terms
;;
LANG | LC_*)
_comp_compgen -- -W '$(locale -a 2>/dev/null)'
_comp_compgen_split -- "$(locale -a 2>/dev/null)"
;;
LANGUAGE)
_comp_delimited : -W '$(locale -a 2>/dev/null)'
Expand Down Expand Up @@ -1576,7 +1576,7 @@ _ip_addresses()
# TODO:API: rename per conventions
_kernel_versions()
{
_comp_compgen -- -W '$(command ls /lib/modules)'
_comp_compgen_split -- "$(command ls /lib/modules)"
}

# This function completes on all available network interfaces
Expand Down Expand Up @@ -1694,26 +1694,26 @@ if [[ $OSTYPE == *@(solaris|aix)* ]]; then
# This function completes on process IDs.
_pids()
{
_comp_compgen -- -W '$(command ps -efo pid | command sed 1d)'
_comp_compgen_split -- "$(command ps -efo pid | command sed 1d)"
}

_pgids()
{
_comp_compgen -- -W '$(command ps -efo pgid | command sed 1d)'
_comp_compgen_split -- "$(command ps -efo pgid | command sed 1d)"
}
_pnames()
{
_comp_compgen -- -X '<defunct>' -W '$(command ps -efo comm | \
command sed -e 1d -e "s:.*/::" -e "s/^-//" | sort -u)'
_comp_compgen_split -X '<defunct>' -- "$(command ps -efo comm |
command sed -e 1d -e 's:.*/::' -e 's/^-//' | sort -u)"
}
else
_pids()
{
_comp_compgen -- -W '$(command ps ax -o pid=)'
_comp_compgen_split -- "$(command ps ax -o pid=)"
}
_pgids()
{
_comp_compgen -- -W '$(command ps ax -o pgid=)'
_comp_compgen_split -- "$(command ps ax -o pgid=)"
}
# @param $1 if -s, don't try to avoid truncated command names
_pnames()
Expand Down Expand Up @@ -1772,12 +1772,12 @@ fi
_uids()
{
if type getent &>/dev/null; then
_comp_compgen -- -W '$(getent passwd | cut -d: -f3)'
_comp_compgen_split -- "$(getent passwd | cut -d: -f3)"
elif type perl &>/dev/null; then
_comp_compgen -- -W '$(perl -e '"'"'while (($uid) = (getpwent)[2]) { print $uid . "\n" }'"'"')'
_comp_compgen_split -- "$(perl -e 'while (($uid) = (getpwent)[2]) { print $uid . "\n" }')"
else
# make do with /etc/passwd
_comp_compgen -- -W '$(cut -d: -f3 /etc/passwd)'
_comp_compgen_split -- "$(cut -d: -f3 /etc/passwd)"
fi
}

Expand All @@ -1787,12 +1787,12 @@ _uids()
_gids()
{
if type getent &>/dev/null; then
_comp_compgen -- -W '$(getent group | cut -d: -f3)'
_comp_compgen_split -- "$(getent group | cut -d: -f3)"
elif type perl &>/dev/null; then
_comp_compgen -- -W '$(perl -e '"'"'while (($gid) = (getgrent)[2]) { print $gid . "\n" }'"'"')'
_comp_compgen_split -- "$(perl -e 'while (($gid) = (getgrent)[2]) { print $gid . "\n" }')"
else
# make do with /etc/group
_comp_compgen -- -W '$(cut -d: -f3 /etc/group)'
_comp_compgen_split -- "$(cut -d: -f3 /etc/group)"
fi
}

Expand Down Expand Up @@ -1862,9 +1862,9 @@ _service()
else
local sysvdirs
_comp_sysvdirs
_comp_compgen -l -- -W '$(command sed -e "y/|/ /" \
-ne "s/^.*\(U\|msg_u\)sage.*{\(.*\)}.*$/\2/p" \
"${sysvdirs[0]}/${prev##*/}" 2>/dev/null) start stop'
_comp_compgen_split -l -- "$(command sed -e 'y/|/ /' \
-ne 's/^.*\(U\|msg_u\)sage.*{\(.*\)}.*$/\2/p' \
"${sysvdirs[0]}/${prev##*/}" 2>/dev/null) start stop"
fi
} &&
complete -F _service service
Expand Down Expand Up @@ -1980,9 +1980,8 @@ _allowed_groups()
# @since 2.12
_comp_selinux_users()
{
_comp_compgen -a -- -W '$(
semanage user -nl 2>/dev/null | awk "{ print \$1 }"
)'
_comp_compgen -a split -- "$(semanage user -nl 2>/dev/null |
awk '{ print $1 }')"
}

# This function completes on valid shells
Expand Down
2 changes: 1 addition & 1 deletion completions/_look
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ _comp_cmd_look()
_comp_initialize -- "$@" || return

if ((cword == 1)); then
COMPREPLY=($(compgen -W '$(look "$cur" 2>/dev/null)' -- "$cur"))
_comp_compgen_split -- "$(look "$cur" 2>/dev/null)"
fi
} &&
complete -F _comp_cmd_look -o default look
Expand Down
3 changes: 1 addition & 2 deletions completions/_umount
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ _comp_cmd_umount()
local cur prev words cword comp_args
_comp_initialize -- "$@" || return

local IFS=$'\n'
COMPREPLY=($(compgen -W '$(mount | cut -d" " -f 3)' -- "$cur"))
_comp_compgen_split -l -- "$(mount | cut -d" " -f 3)"
} &&
complete -F _comp_cmd_umount -o dirnames umount

Expand Down
3 changes: 1 addition & 2 deletions completions/_umount.linux
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ _comp_cmd_umount()
# unmounting usb devices with pretty names.
_comp_cmd_umount__linux_fstab </proc/mounts
else
local IFS=$'\n'
COMPREPLY=($(compgen -W '$(mount | cut -d" " -f 3)' -- "$cur"))
_comp_compgen_split -l -- "$(mount | cut -d" " -f 3)"
fi
} &&
complete -F _comp_cmd_umount -o dirnames umount
Expand Down
6 changes: 3 additions & 3 deletions completions/_xm
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ _comp_cmd_xm()
;;
create)
_comp_compgen_filedir
COMPREPLY+=(
$(compgen -W '$(command ls /etc/xen 2>/dev/null)' \
-- "$cur"))
_comp_compgen -a split -- "$(
command ls /etc/xen 2>/dev/null
)"
;;
new)
case $prev in
Expand Down
9 changes: 4 additions & 5 deletions completions/_yum
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,16 @@ _comp_cmd_yum()
_comp_compgen_filedir -d
;;
--enablerepo)
COMPREPLY=($(compgen -W '$(_yum_repolist disabled)' -- "$cur"))
_comp_compgen_split -- "$(_yum_repolist disabled)"
;;
--disablerepo)
COMPREPLY=($(compgen -W '$(_yum_repolist enabled)' -- "$cur"))
_comp_compgen_split -- "$(_yum_repolist enabled)"
;;
--disableexcludes)
COMPREPLY=($(compgen -W '$(_yum_repolist all) all main' \
-- "$cur"))
_comp_compgen_split -- "$(_yum_repolist all) all main"
;;
--enableplugin | --disableplugin)
COMPREPLY=($(compgen -W '$(_yum_plugins)' -- "$cur"))
_comp_compgen_split -- "$(_yum_plugins)"
;;
--color)
_comp_compgen -- -W 'always auto never'
Expand Down
5 changes: 4 additions & 1 deletion completions/apt-cache
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ _comp_cmd_apt_cache__sources()
# @since 2.12
_comp_xfunc_apt_cache_src_packages()
{
compgen -W '$(_comp_cmd_apt_cache__sources apt-cache "$cur")' -- "$cur"
local ret
_comp_compgen -v ret split -- \
"$(_comp_cmd_apt_cache__sources apt-cache "$cur")" &&
printf '%s\n' "${ret[@]}"
}

_comp_deprecate_func 2.12 _apt_cache_packages _comp_xfunc_apt_cache_packages
Expand Down
2 changes: 1 addition & 1 deletion completions/avahi-browse
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ _comp_cmd_avahi_browse()
;;
esac
done
COMPREPLY=($(compgen -W '$("$1" --dump-db --no-db-lookup)' -- "$cur"))
_comp_compgen_split -- "$("$1" --dump-db --no-db-lookup)"

} &&
complete -F _comp_cmd_avahi_browse avahi-browse avahi-browse-domains
Expand Down
2 changes: 1 addition & 1 deletion completions/bind
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ _comp_cmd_bind()
return
;;
-*[qu])
COMPREPLY=($(compgen -W '$("$1" -l)' -- "$cur"))
_comp_compgen_split -- "$("$1" -l)"
return
;;
esac
Expand Down
3 changes: 2 additions & 1 deletion completions/bts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ _comp_cmd_bts__cached_bugs()
_comp_cmd_bts__src_packages_with_prefix()
{
local ppn=${cur:4} # partial package name, after stripping "src:"
_comp_compgen -ac "$ppn" -- -P "src:" -W '$(_comp_xfunc apt-cache sources "$ppn")'
_comp_compgen -ac "$ppn" split -P "src:" -- \
"$(_comp_xfunc apt-cache sources "$ppn")"
}

_comp_cmd_bts()
Expand Down
5 changes: 2 additions & 3 deletions completions/ccze
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ _comp_cmd_ccze()
return
;;
--plugin | -${noargopts}p)
COMPREPLY=($(compgen -W '$("$1" --list-plugins | command \
sed -ne "s/^\([a-z0-9]\{1,\}\)[[:space:]]\{1,\}|.*/\1/p")' \
-- "$cur"))
_comp_compgen_split -- "$("$1" --list-plugins | command \
sed -ne 's/^\([a-z0-9]\{1,\}\)[[:space:]]\{1,\}|.*/\1/p')"
return
;;
esac
Expand Down
14 changes: 4 additions & 10 deletions completions/checksec
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,12 @@ _comp_cmd_checksec()
return
;;
--format)
COMPREPLY=($(compgen -W '$("$1" --help 2>/dev/null |
command sed \
-e "s/[{,}]/ /g" \
-ne "s/^[[:space:]]*--format=//p"
)' -- "$cur"))
_comp_compgen_split -- "$("$1" --help 2>/dev/null |
command sed -ne 's/[{,}]/ /g;s/^[[:space:]]*--format=//p')"
;;
--output)
COMPREPLY=($(compgen -W '$("$1" --help 2>/dev/null |
command sed \
-e "s/[{,}]/ /g" \
-ne "s/^[[:space:]]*--output=//p"
)' -- "$cur"))
_comp_compgen_split -- "$("$1" --help 2>/dev/null |
command sed -ne 's/[{,}]/ /g;s/^[[:space:]]*--output=//p')"
;;
esac

Expand Down
3 changes: 1 addition & 2 deletions completions/cowsay
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ _comp_cmd_cowsay()

case $prev in
-f)
COMPREPLY=($(compgen -W \
'$(cowsay -l 2>/dev/null | tail -n +2)' -- "$cur"))
_comp_compgen_split -- "$(cowsay -l 2>/dev/null | tail -n +2)"
return
;;
esac
Expand Down
5 changes: 2 additions & 3 deletions completions/cpan2dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ _comp_cmd_cpan2dist()
case $prev in
--format)
# should remove ":" from COMP_WORDBREAKS, but doesn't work (?)
COMPREPLY=($(compgen -W '$(perl -MCPANPLUS::Dist -e \
"print map { \"\$_\n\" } CPANPLUS::Dist->dist_types")' \
-- "$cur"))
_comp_compgen_split -- "$(perl -MCPANPLUS::Dist -e \
'print map { "$_n" } CPANPLUS::Dist->dist_types')"
return
;;
--banlist | --ignorelist | --modulelist | --logfile)
Expand Down
2 changes: 1 addition & 1 deletion completions/cryptsetup
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

_comp_cmd_cryptsetup__name()
{
COMPREPLY=($(compgen -X control -W '$(command ls /dev/mapper)' -- "$cur"))
_comp_compgen_split -X control -- "$(command ls /dev/mapper)"
}

_comp_cmd_cryptsetup__device()
Expand Down
4 changes: 2 additions & 2 deletions completions/cvs
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,8 @@ _comp_cmd_cvs()
esac

_comp_compgen_help -- --help-options
_comp_compgen -a -- -W '$(_cvs_commands) --help
--help-commands --help-options --version'
_comp_compgen -a split -- "$(_cvs_commands) --help
--help-commands --help-options --version"
;;
esac

Expand Down
11 changes: 6 additions & 5 deletions completions/dict
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ _comp_cmd_dict()
# shellcheck disable=SC2254
case $prev in
--database | -info | -${noargopts}[di])
COMPREPLY=($(compgen -W '$(_dictdata -D)' -- "$cur"))
_comp_compgen_split -- "$(_dictdata -D)"
return
;;
--strategy | -${noargopts}s)
COMPREPLY=($(compgen -W '$(_dictdata -S)' -- "$cur"))
_comp_compgen_split -- "$(_dictdata -S)"
return
;;
esac
Expand All @@ -57,10 +57,11 @@ _comp_cmd_dict()
# it down with grep if $cur looks like something that's safe to embed
# in a pattern instead.
if [[ $cur == +([-A-Za-z0-9/.]) ]]; then
COMPREPLY=($(compgen -W \
'$(command grep "^${cur//./\\.}" "$dictfile")' -- "$cur"))
_comp_compgen_split -- "$(
command grep "^${cur//./\\.}" "$dictfile"
)"
else
COMPREPLY=($(compgen -W '$(cat "$dictfile")' -- "$cur"))
_comp_compgen_split -- "$(cat "$dictfile")"
fi
fi
} &&
Expand Down
31 changes: 15 additions & 16 deletions completions/ebtables
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,29 @@ _comp_cmd_ebtables()
# shellcheck disable=SC2254
case $prev in
-${noargopts}[AIDPFXLZ])
COMPREPLY=($(compgen -W '`"$1" ${table:+-t "$table"} -L 2>/dev/null | \
command sed -ne "$chain"`' -- "$cur"))
_comp_compgen_split -- "$(
"$1" ${table:+-t "$table"} -L 2>/dev/null |
command sed -ne "$chain"
)"
;;
-${noargopts}t)
_comp_compgen -- -W 'nat filter broute'
;;
-${noargopts}j)
if [[ $table == "filter" || ! $table ]]; then
COMPREPLY=($(compgen -W '$targets
$("$1" ${table:+-t "$table"} -L 2>/dev/null | \
command sed -n -e "s/INPUT\|OUTPUT\|FORWARD//" \
-e "$chain")' \
-- "$cur"))
_comp_compgen -- -W '$targets'
_comp_compgen -a split -- "$("$1" ${table:+-t "$table"} -L \
2>/dev/null | command sed -n -e \
"s/INPUT\|OUTPUT\|FORWARD//" -e "$chain")"
elif [[ $table == "nat" ]]; then
COMPREPLY=($(compgen -W '$targets
$("$1" -t "$table" -L 2>/dev/null | \
command sed -n -e "s/OUTPUT|PREROUTING|POSTROUTING//" \
-e "$chain")' \
-- "$cur"))
_comp_compgen -- -W '$targets'
_comp_compgen -a split -- "$("$1" -t "$table" -L 2>/dev/null |
command sed -n -e "s/OUTPUT|PREROUTING|POSTROUTING//" \
-e "$chain")"
elif [[ $table == "broute" ]]; then
COMPREPLY=($(compgen -W 'ACCEPT DROP
$("$1" -t "$table" -L 2>/dev/null | \
command sed -n -e "s/BROUTING//" -e "$chain")' \
-- "$cur"))
_comp_compgen -- -W 'ACCEPT DROP'
_comp_compgen -a split -- "$("$1" -t "$table" -L 2>/dev/null |
command sed -n -e "s/BROUTING//" -e "$chain")"
fi
;;
*)
Expand Down
9 changes: 4 additions & 5 deletions completions/fbgs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ _comp_cmd_fbgs()

case "$prev" in
-f | --font)
local IFS=$'\n'
COMPREPLY=($(compgen -W '$(fc-list 2>/dev/null)' -- "$cur"))
_comp_compgen_split -l -- "$(fc-list 2>/dev/null)"
return
;;
-m | --mode)
COMPREPLY=($(compgen -W '$(command sed \
-n "/^mode/{s/^mode \{1,\}\"\([^\"]\{1,\}\)\"/\1/g;p}" \
/etc/fb.modes 2>/dev/null)' -- "$cur"))
_comp_compgen_split -- "$(command sed \
-n '/^mode/{s/^mode \{1,\}"\([^"]\{1,\}\)"/\1/g;p}' \
/etc/fb.modes 2>/dev/null)"
return
;;
-d | --device)
Expand Down
Loading

0 comments on commit 08fba21

Please sign in to comment.