Skip to content

Commit 8bc4c93

Browse files
committed
refactor: use _comp_compgen_split for -W '$(...)'
1 parent 49a11d2 commit 8bc4c93

Some content is hidden

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

67 files changed

+223
-255
lines changed

bash_completion

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,7 @@ _comp_variable_assignments()
11831183
_terms
11841184
;;
11851185
LANG | LC_*)
1186-
_comp_compgen -- -W '$(locale -a 2>/dev/null)'
1186+
_comp_compgen_split -- "$(locale -a 2>/dev/null)"
11871187
;;
11881188
LANGUAGE)
11891189
_comp_delimited : -W '$(locale -a 2>/dev/null)'
@@ -1573,7 +1573,7 @@ _ip_addresses()
15731573
# TODO:API: rename per conventions
15741574
_kernel_versions()
15751575
{
1576-
_comp_compgen -- -W '$(command ls /lib/modules)'
1576+
_comp_compgen_split -- "$(command ls /lib/modules)"
15771577
}
15781578

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

16971697
_pgids()
16981698
{
1699-
_comp_compgen -- -W '$(command ps -efo pgid | command sed 1d)'
1699+
_comp_compgen_split -- "$(command ps -efo pgid | command sed 1d)"
17001700
}
17011701
_pnames()
17021702
{
1703-
_comp_compgen -- -X '<defunct>' -W '$(command ps -efo comm | \
1704-
command sed -e 1d -e "s:.*/::" -e "s/^-//" | sort -u)'
1703+
_comp_compgen_split -X '<defunct>' -- "$(command ps -efo comm |
1704+
command sed -e 1d -e 's:.*/::' -e 's/^-//' | sort -u)"
17051705
}
17061706
else
17071707
_pids()
17081708
{
1709-
_comp_compgen -- -W '$(command ps ax -o pid=)'
1709+
_comp_compgen_split -- "$(command ps ax -o pid=)"
17101710
}
17111711
_pgids()
17121712
{
1713-
_comp_compgen -- -W '$(command ps ax -o pgid=)'
1713+
_comp_compgen_split -- "$(command ps ax -o pgid=)"
17141714
}
17151715
# @param $1 if -s, don't try to avoid truncated command names
17161716
_pnames()
@@ -1769,12 +1769,12 @@ fi
17691769
_uids()
17701770
{
17711771
if type getent &>/dev/null; then
1772-
_comp_compgen -- -W '$(getent passwd | cut -d: -f3)'
1772+
_comp_compgen_split -- "$(getent passwd | cut -d: -f3)"
17731773
elif type perl &>/dev/null; then
1774-
_comp_compgen -- -W '$(perl -e '"'"'while (($uid) = (getpwent)[2]) { print $uid . "\n" }'"'"')'
1774+
_comp_compgen_split -- "$(perl -e 'while (($uid) = (getpwent)[2]) { print $uid . "\n" }')"
17751775
else
17761776
# make do with /etc/passwd
1777-
_comp_compgen -- -W '$(cut -d: -f3 /etc/passwd)'
1777+
_comp_compgen_split -- "$(cut -d: -f3 /etc/passwd)"
17781778
fi
17791779
}
17801780

@@ -1784,12 +1784,12 @@ _uids()
17841784
_gids()
17851785
{
17861786
if type getent &>/dev/null; then
1787-
_comp_compgen -- -W '$(getent group | cut -d: -f3)'
1787+
_comp_compgen_split -- "$(getent group | cut -d: -f3)"
17881788
elif type perl &>/dev/null; then
1789-
_comp_compgen -- -W '$(perl -e '"'"'while (($gid) = (getgrent)[2]) { print $gid . "\n" }'"'"')'
1789+
_comp_compgen_split -- "$(perl -e 'while (($gid) = (getgrent)[2]) { print $gid . "\n" }')"
17901790
else
17911791
# make do with /etc/group
1792-
_comp_compgen -- -W '$(cut -d: -f3 /etc/group)'
1792+
_comp_compgen_split -- "$(cut -d: -f3 /etc/group)"
17931793
fi
17941794
}
17951795

@@ -1859,9 +1859,9 @@ _service()
18591859
else
18601860
local sysvdirs
18611861
_comp_sysvdirs
1862-
_comp_compgen -l -- -W '$(command sed -e "y/|/ /" \
1863-
-ne "s/^.*\(U\|msg_u\)sage.*{\(.*\)}.*$/\2/p" \
1864-
"${sysvdirs[0]}/${prev##*/}" 2>/dev/null) start stop'
1862+
_comp_compgen_split -l -- "$(command sed -e 'y/|/ /' \
1863+
-ne 's/^.*\(U\|msg_u\)sage.*{\(.*\)}.*$/\2/p' \
1864+
"${sysvdirs[0]}/${prev##*/}" 2>/dev/null) start stop"
18651865
fi
18661866
} &&
18671867
complete -F _service service
@@ -1977,9 +1977,8 @@ _allowed_groups()
19771977
# @since 2.12
19781978
_comp_selinux_users()
19791979
{
1980-
_comp_compgen -a -- -W '$(
1981-
semanage user -nl 2>/dev/null | awk "{ print \$1 }"
1982-
)'
1980+
_comp_compgen -a split -- "$(semanage user -nl 2>/dev/null |
1981+
awk '{ print $1 }')"
19831982
}
19841983

19851984
# This function completes on valid shells

completions/_look

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ _comp_cmd_look()
99
_comp_initialize -- "$@" || return
1010

1111
if ((cword == 1)); then
12-
COMPREPLY=($(compgen -W '$(look "$cur" 2>/dev/null)' -- "$cur"))
12+
_comp_compgen_split -- "$(look "$cur" 2>/dev/null)"
1313
fi
1414
} &&
1515
complete -F _comp_cmd_look -o default look

completions/_umount

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ _comp_cmd_umount()
1616
local cur prev words cword comp_args
1717
_comp_initialize -- "$@" || return
1818

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

completions/_umount.linux

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ _comp_cmd_umount()
130130
# unmounting usb devices with pretty names.
131131
_comp_cmd_umount__linux_fstab </proc/mounts
132132
else
133-
local IFS=$'\n'
134-
COMPREPLY=($(compgen -W '$(mount | cut -d" " -f 3)' -- "$cur"))
133+
_comp_compgen_split -l -- "$(mount | cut -d" " -f 3)"
135134
fi
136135
} &&
137136
complete -F _comp_cmd_umount -o dirnames umount

completions/_xm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ _comp_cmd_xm()
185185
;;
186186
create)
187187
_comp_compgen_filedir
188-
COMPREPLY+=(
189-
$(compgen -W '$(command ls /etc/xen 2>/dev/null)' \
190-
-- "$cur"))
188+
_comp_compgen -a split -- "$(
189+
command ls /etc/xen 2>/dev/null
190+
)"
191191
;;
192192
new)
193193
case $prev in

completions/_yum

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,16 @@ _comp_cmd_yum()
105105
_comp_compgen_filedir -d
106106
;;
107107
--enablerepo)
108-
COMPREPLY=($(compgen -W '$(_yum_repolist disabled)' -- "$cur"))
108+
_comp_compgen_split -- "$(_yum_repolist disabled)"
109109
;;
110110
--disablerepo)
111-
COMPREPLY=($(compgen -W '$(_yum_repolist enabled)' -- "$cur"))
111+
_comp_compgen_split -- "$(_yum_repolist enabled)"
112112
;;
113113
--disableexcludes)
114-
COMPREPLY=($(compgen -W '$(_yum_repolist all) all main' \
115-
-- "$cur"))
114+
_comp_compgen_split -- "$(_yum_repolist all) all main"
116115
;;
117116
--enableplugin | --disableplugin)
118-
COMPREPLY=($(compgen -W '$(_yum_plugins)' -- "$cur"))
117+
_comp_compgen_split -- "$(_yum_plugins)"
119118
;;
120119
--color)
121120
_comp_compgen -- -W 'always auto never'

completions/apt-cache

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ _comp_cmd_apt_cache__sources()
3636
# @since 2.12
3737
_comp_xfunc_apt_cache_src_packages()
3838
{
39-
compgen -W '$(_comp_cmd_apt_cache__sources apt-cache "$cur")' -- "$cur"
39+
local ret
40+
_comp_compgen -v ret split -- \
41+
"$(_comp_cmd_apt_cache__sources apt-cache "$cur")" &&
42+
printf '%s\n' "${ret[@]}"
4043
}
4144

4245
_comp_deprecate_func 2.12 _apt_cache_packages _comp_xfunc_apt_cache_packages

completions/avahi-browse

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ _comp_cmd_avahi_browse()
3434
;;
3535
esac
3636
done
37-
COMPREPLY=($(compgen -W '$("$1" --dump-db --no-db-lookup)' -- "$cur"))
37+
_comp_compgen_split -- "$("$1" --dump-db --no-db-lookup)"
3838

3939
} &&
4040
complete -F _comp_cmd_avahi_browse avahi-browse avahi-browse-domains

completions/bind

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ _comp_cmd_bind()
1919
return
2020
;;
2121
-*[qu])
22-
COMPREPLY=($(compgen -W '$("$1" -l)' -- "$cur"))
22+
_comp_compgen_split -- "$("$1" -l)"
2323
return
2424
;;
2525
esac

completions/bts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ _comp_cmd_bts__cached_bugs()
1818
_comp_cmd_bts__src_packages_with_prefix()
1919
{
2020
local ppn=${cur:4} # partial package name, after stripping "src:"
21-
_comp_compgen -ac "$ppn" -- -P "src:" -W '$(_comp_xfunc apt-cache sources "$ppn")'
21+
_comp_compgen -ac "$ppn" split -P "src:" -- \
22+
"$(_comp_xfunc apt-cache sources "$ppn")"
2223
}
2324

2425
_comp_cmd_bts()

0 commit comments

Comments
 (0)