Skip to content

Commit 08fba21

Browse files
committed
refactor: use _comp_compgen_split for -W '$(...)'
1 parent cb347cb commit 08fba21

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)'
@@ -1576,7 +1576,7 @@ _ip_addresses()
15761576
# TODO:API: rename per conventions
15771577
_kernel_versions()
15781578
{
1579-
_comp_compgen -- -W '$(command ls /lib/modules)'
1579+
_comp_compgen_split -- "$(command ls /lib/modules)"
15801580
}
15811581

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

17001700
_pgids()
17011701
{
1702-
_comp_compgen -- -W '$(command ps -efo pgid | command sed 1d)'
1702+
_comp_compgen_split -- "$(command ps -efo pgid | command sed 1d)"
17031703
}
17041704
_pnames()
17051705
{
1706-
_comp_compgen -- -X '<defunct>' -W '$(command ps -efo comm | \
1707-
command sed -e 1d -e "s:.*/::" -e "s/^-//" | sort -u)'
1706+
_comp_compgen_split -X '<defunct>' -- "$(command ps -efo comm |
1707+
command sed -e 1d -e 's:.*/::' -e 's/^-//' | sort -u)"
17081708
}
17091709
else
17101710
_pids()
17111711
{
1712-
_comp_compgen -- -W '$(command ps ax -o pid=)'
1712+
_comp_compgen_split -- "$(command ps ax -o pid=)"
17131713
}
17141714
_pgids()
17151715
{
1716-
_comp_compgen -- -W '$(command ps ax -o pgid=)'
1716+
_comp_compgen_split -- "$(command ps ax -o pgid=)"
17171717
}
17181718
# @param $1 if -s, don't try to avoid truncated command names
17191719
_pnames()
@@ -1772,12 +1772,12 @@ fi
17721772
_uids()
17731773
{
17741774
if type getent &>/dev/null; then
1775-
_comp_compgen -- -W '$(getent passwd | cut -d: -f3)'
1775+
_comp_compgen_split -- "$(getent passwd | cut -d: -f3)"
17761776
elif type perl &>/dev/null; then
1777-
_comp_compgen -- -W '$(perl -e '"'"'while (($uid) = (getpwent)[2]) { print $uid . "\n" }'"'"')'
1777+
_comp_compgen_split -- "$(perl -e 'while (($uid) = (getpwent)[2]) { print $uid . "\n" }')"
17781778
else
17791779
# make do with /etc/passwd
1780-
_comp_compgen -- -W '$(cut -d: -f3 /etc/passwd)'
1780+
_comp_compgen_split -- "$(cut -d: -f3 /etc/passwd)"
17811781
fi
17821782
}
17831783

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

@@ -1862,9 +1862,9 @@ _service()
18621862
else
18631863
local sysvdirs
18641864
_comp_sysvdirs
1865-
_comp_compgen -l -- -W '$(command sed -e "y/|/ /" \
1866-
-ne "s/^.*\(U\|msg_u\)sage.*{\(.*\)}.*$/\2/p" \
1867-
"${sysvdirs[0]}/${prev##*/}" 2>/dev/null) start stop'
1865+
_comp_compgen_split -l -- "$(command sed -e 'y/|/ /' \
1866+
-ne 's/^.*\(U\|msg_u\)sage.*{\(.*\)}.*$/\2/p' \
1867+
"${sysvdirs[0]}/${prev##*/}" 2>/dev/null) start stop"
18681868
fi
18691869
} &&
18701870
complete -F _service service
@@ -1980,9 +1980,8 @@ _allowed_groups()
19801980
# @since 2.12
19811981
_comp_selinux_users()
19821982
{
1983-
_comp_compgen -a -- -W '$(
1984-
semanage user -nl 2>/dev/null | awk "{ print \$1 }"
1985-
)'
1983+
_comp_compgen -a split -- "$(semanage user -nl 2>/dev/null |
1984+
awk '{ print $1 }')"
19861985
}
19871986

19881987
# 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)