Skip to content

Commit 49997d0

Browse files
akinomyogascop
andcommitted
fix: use _comp_compgen_split to avoid extra expansions by -W "$(...)"
Co-authored-by: Ville Skyttä <ville.skytta@iki.fi>
1 parent 513ed46 commit 49997d0

Some content is hidden

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

76 files changed

+287
-319
lines changed

bash_completion

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,23 +1524,23 @@ _configured_interfaces()
15241524
# Debian system
15251525
_comp_expand_glob files '/etc/network/interfaces /etc/network/interfaces.d/*'
15261526
((${#files[@]})) || return 0
1527-
_comp_compgen -- -W "$(command sed -ne 's|^iface \([^ ]\{1,\}\).*$|\1|p' \
1528-
"${files[@]}" 2>/dev/null)"
1527+
_comp_compgen_split -- "$(command sed -ne \
1528+
's|^iface \([^ ]\{1,\}\).*$|\1|p' "${files[@]}" 2>/dev/null)"
15291529
elif [[ -f /etc/SuSE-release ]]; then
15301530
# SuSE system
15311531
_comp_expand_glob files '/etc/sysconfig/network/ifcfg-*'
15321532
((${#files[@]})) || return 0
1533-
_comp_compgen -- -W "$(printf '%s\n' "${files[@]}" |
1533+
_comp_compgen_split -- "$(printf '%s\n' "${files[@]}" |
15341534
command sed -ne 's|.*ifcfg-\([^*].*\)$|\1|p')"
15351535
elif [[ -f /etc/pld-release ]]; then
15361536
# PLD Linux
1537-
_comp_compgen -- -W "$(command ls -B /etc/sysconfig/interfaces |
1537+
_comp_compgen_split -- "$(command ls -B /etc/sysconfig/interfaces |
15381538
command sed -ne 's|.*ifcfg-\([^*].*\)$|\1|p')"
15391539
else
15401540
# Assume Red Hat
15411541
_comp_expand_glob files '/etc/sysconfig/network-scripts/ifcfg-*'
15421542
((${#files[@]})) || return 0
1543-
_comp_compgen -- -W "$(printf '%s\n' "${files[@]}" |
1543+
_comp_compgen_split -- "$(printf '%s\n' "${files[@]}" |
15441544
command sed -ne 's|.*ifcfg-\([^*].*\)$|\1|p')"
15451545
fi
15461546
}
@@ -1889,7 +1889,7 @@ _modules()
18891889
{
18901890
local modpath
18911891
modpath=/lib/modules/$1
1892-
_comp_compgen -- -W "$(command ls -RL "$modpath" 2>/dev/null |
1892+
_comp_compgen_split -- "$(command ls -RL "$modpath" 2>/dev/null |
18931893
command sed -ne 's/^\(.*\)\.k\{0,1\}o\(\.[gx]z\)\{0,1\}$/\1/p' \
18941894
-e 's/^\(.*\)\.ko\.zst$/\1/p')"
18951895
}
@@ -1899,7 +1899,7 @@ _modules()
18991899
# TODO:API: rename per conventions (+ include "kernel" in the name)
19001900
_installed_modules()
19011901
{
1902-
_comp_compgen -c "$1" -- -W "$(PATH="$PATH:/sbin" lsmod |
1902+
_comp_compgen -c "$1" split -- "$(PATH="$PATH:/sbin" lsmod |
19031903
awk '{if (NR != 1) print $1}')"
19041904
}
19051905

@@ -1961,8 +1961,8 @@ _allowed_users()
19611961
if _complete_as_root; then
19621962
_comp_compgen -c "${1:-$cur}" -- -u
19631963
else
1964-
_comp_compgen -c "${1:-$cur}" -- -W \
1965-
"$(id -un 2>/dev/null || whoami 2>/dev/null)"
1964+
_comp_compgen -c "${1:-$cur}" split -- "$(id -un 2>/dev/null ||
1965+
whoami 2>/dev/null)"
19661966
fi
19671967
}
19681968

@@ -1972,8 +1972,8 @@ _allowed_groups()
19721972
if _complete_as_root; then
19731973
_comp_compgen -c "$1" -- -g
19741974
else
1975-
_comp_compgen -c "$1" -- -W \
1976-
"$(id -Gn 2>/dev/null || groups 2>/dev/null)"
1975+
_comp_compgen -c "$1" split -- "$(id -Gn 2>/dev/null ||
1976+
groups 2>/dev/null)"
19771977
fi
19781978
}
19791979

@@ -2107,15 +2107,16 @@ _count_args()
21072107
# TODO:API: rename per conventions
21082108
_pci_ids()
21092109
{
2110-
_comp_compgen -a -- -W "$(PATH="$PATH:/sbin" lspci -n | awk '{print $3}')"
2110+
_comp_compgen -a split -- "$(PATH="$PATH:/sbin" lspci -n |
2111+
awk '{print $3}')"
21112112
}
21122113

21132114
# This function completes on USB IDs
21142115
#
21152116
# TODO:API: rename per conventions
21162117
_usb_ids()
21172118
{
2118-
_comp_compgen -a -- -W "$(PATH="$PATH:/sbin" lsusb | awk '{print $6}')"
2119+
_comp_compgen -a split -- "$(PATH="$PATH:/sbin" lsusb | awk '{print $6}')"
21192120
}
21202121

21212122
# CD device names
@@ -2136,7 +2137,7 @@ _dvd_devices()
21362137
# TODO:API: rename per conventions
21372138
_terms()
21382139
{
2139-
_comp_compgen -a -- -W "$({
2140+
_comp_compgen -a split -- "$({
21402141
command sed -ne 's/^\([^[:space:]#|]\{2,\}\)|.*/\1/p' /etc/termcap
21412142
{
21422143
toe -a || toe
@@ -2694,7 +2695,7 @@ _comp_longopt()
26942695
[[ $was_split ]] && return
26952696

26962697
if [[ $cur == -* ]]; then
2697-
_comp_compgen -- -W "$(LC_ALL=C $1 --help 2>&1 |
2698+
_comp_compgen_split -- "$(LC_ALL=C $1 --help 2>&1 |
26982699
while read -r line; do
26992700
[[ $line =~ --[A-Za-z0-9]+([-_][A-Za-z0-9]+)*=? ]] &&
27002701
printf '%s\n' "${BASH_REMATCH[0]}"

completions/2to3

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ _comp_cmd_2to3()
1010
return
1111
;;
1212
-f | --fix | -x | --nofix)
13-
COMPREPLY=($(compgen -W \
14-
"$("$1" --list-fixes 2>/dev/null | command sed -e 1d)" -- "$cur"))
13+
_comp_compgen_split -- "$(
14+
"$1" --list-fixes 2>/dev/null | command sed -e 1d
15+
)"
1516
return
1617
;;
1718
-j | --processes)

completions/7z

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ _comp_cmd_7z()
101101
_comp_compgen -a filedir '@(7z?(.001)|arj|bz2|cab|cb7|chm|cpio|deb|dmg|flv|gem|img|iso|lz[ah]|lzma?(86)|msi|pmd|[rx]ar|rpm|sw[fm]|?(g)tar|taz|?(t)[bglx]z|tb?(z)2|vhd|wim|Z)'
102102
else
103103
if [[ ${words[1]} == d ]]; then
104-
local IFS=$'\n'
105-
COMPREPLY=($(compgen -W "$("$1" l "${words[2]}" \
106-
-slt 2>/dev/null | command sed -n '/^Path =/s/^Path = \(.*\)$/\1/p' \
107-
2>/dev/null | tail -n+2)" -- "$cur"))
104+
_comp_compgen_split -l -- "$(
105+
"$1" l "${words[2]}" -slt 2>/dev/null | command sed -n \
106+
'/^Path =/s/^Path = \(.*\)$/\1/p' 2>/dev/null | tail -n+2
107+
)"
108108
compopt -o filenames
109109
else
110110
_comp_compgen_filedir

completions/_mock

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ _comp_cmd_mock()
2727
return
2828
;;
2929
-r | --root)
30-
COMPREPLY=($(compgen -W "$(command ls "$cfgdir")" -- "$cur"))
30+
_comp_compgen_split -- "$(command ls "$cfgdir")"
3131
COMPREPLY=(${COMPREPLY[@]/%.cfg/})
3232
return
3333
;;
@@ -44,9 +44,8 @@ _comp_cmd_mock()
4444
# (e.g. ix86 chroot builds in x86_64 mock host)
4545
# This would actually depend on what the target root
4646
# can be used to build for...
47-
COMPREPLY=($(compgen -W "$(command rpm --showrc |
48-
command sed -ne 's/^\s*compatible\s\s*archs\s*:\s*\(.*\)/\1/i p')" \
49-
-- "$cur"))
47+
_comp_compgen_split -- "$(command rpm --showrc | command sed -ne \
48+
's/^\s*compatible\s\s*archs\s*:\s*\(.*\)/\1/i p')"
5049
return
5150
;;
5251
--enable-plugin | --disable-plugin)

completions/_mount

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ _comp_cmd_mount()
3333
if [[ $cur == *:* ]]; then
3434
for sm in "$(type -P showmount)" {,/usr}/{,s}bin/showmount; do
3535
[[ -x $sm ]] || continue
36-
COMPREPLY=($(compgen -W "$("$sm" -e ${cur%%:*} |
37-
awk 'NR>1 {print $1}')" -- "${cur#*:}"))
36+
_comp_compgen -c "${cur#*:}" split -- "$(
37+
"$sm" -e ${cur%%:*} | awk 'NR>1 {print $1}'
38+
)"
3839
return
3940
done
4041
fi
@@ -43,21 +44,27 @@ _comp_cmd_mount()
4344
host=${cur#//}
4445
host=${host%%/*}
4546
if [[ $host ]]; then
46-
COMPREPLY=($(compgen -P "//$host" -W \
47-
"$(smbclient -d 0 -NL "$host" 2>/dev/null |
47+
_comp_compgen -c "${cur#//"$host"}" split -P "//$host" -- "$(
48+
smbclient -d 0 -NL "$host" 2>/dev/null |
4849
command sed -ne '/^[[:blank:]]*Sharename/,/^$/p' |
49-
command sed -ne '3,$s|^[^A-Za-z]*\([^[:blank:]]*\).*$|/\1|p')" \
50-
-- "${cur#//"$host"}"))
50+
command sed -ne '3,$s|^[^A-Za-z]*\([^[:blank:]]*\).*$|/\1|p'
51+
)"
5152
fi
5253
elif [[ -r /etc/vfstab ]]; then
5354
# Solaris
54-
COMPREPLY=($(compgen -W "$(awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}' /etc/vfstab)" -- "$cur"))
55+
_comp_compgen_split -- "$(
56+
awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}' /etc/vfstab
57+
)"
5558
elif [[ ! -e /etc/fstab ]]; then
5659
# probably Cygwin
57-
COMPREPLY=($(compgen -W "$("$1" | awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}')" -- "$cur"))
60+
_comp_compgen_split -- "$(
61+
"$1" | awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}'
62+
)"
5863
else
5964
# probably BSD
60-
COMPREPLY=($(compgen -W "$(awk '! /^[ \t]*#/ {if ($2 ~ /\//) print $2}' /etc/fstab)" -- "$cur"))
65+
_comp_compgen_split -- "$(
66+
awk '! /^[ \t]*#/ {if ($2 ~ /\//) print $2}' /etc/fstab
67+
)"
6168
fi
6269
} &&
6370
complete -F _comp_cmd_mount -o default -o dirnames mount

completions/_mount.linux

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,9 @@ _comp_cmd_mount()
223223
if [[ $cur == *:* ]]; then
224224
for sm in "$(type -P showmount)" {,/usr}/{,s}bin/showmount; do
225225
[[ -x $sm ]] || continue
226-
COMPREPLY=($(compgen -W "$("$sm" -e ${cur%%:*} |
227-
awk 'NR>1 {print $1}')" -- "${cur#*:}"))
226+
_comp_compgen -c "${cur#*:}" split -- "$(
227+
"$sm" -e ${cur%%:*} | awk 'NR>1 {print $1}'
228+
)"
228229
return
229230
done
230231
fi
@@ -233,11 +234,11 @@ _comp_cmd_mount()
233234
host=${cur#//}
234235
host=${host%%/*}
235236
if [[ $host ]]; then
236-
COMPREPLY=($(compgen -P "//$host" -W \
237-
"$(smbclient -d 0 -NL "$host" 2>/dev/null |
237+
_comp_compgen -c "${cur#//"$host"}" split -P "//$host" -- "$(
238+
smbclient -d 0 -NL "$host" 2>/dev/null |
238239
command sed -ne '/^[[:blank:]]*Sharename/,/^$/p' |
239-
command sed -ne '3,$s|^[^A-Za-z]*\([^[:blank:]]*\).*$|/\1|p')" \
240-
-- "${cur#//"$host"}"))
240+
command sed -ne '3,$s|^[^A-Za-z]*\([^[:blank:]]*\).*$|/\1|p'
241+
)"
241242
fi
242243
fi
243244

completions/_nmcli

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,26 @@
55

66
_comp_cmd_nmcli__con_id()
77
{
8-
local IFS=$'\n'
9-
COMPREPLY=($(compgen -W "$(nmcli con list 2>/dev/null |
10-
tail -n +2 | awk -F ' {2,}' '{print $1 }')" -- "$cur"))
8+
_comp_compgen_split -l -- "$(nmcli con list 2>/dev/null |
9+
tail -n +2 | awk -F ' {2,}' '{print $1 }')"
1110
}
1211

1312
_comp_cmd_nmcli__con_uuid()
1413
{
15-
COMPREPLY=($(compgen -W "$(nmcli con list 2>/dev/null |
16-
tail -n +2 | awk -F ' {2,}' '{print $2}')" -- "$cur"))
14+
_comp_compgen_split -- "$(nmcli con list 2>/dev/null |
15+
tail -n +2 | awk -F ' {2,}' '{print $2}')"
1716
}
1817

1918
_comp_cmd_nmcli__ap_ssid()
2019
{
21-
local IFS=$'\n'
22-
COMPREPLY=($(compgen -W "$(nmcli dev wifi list 2>/dev/null |
23-
tail -n +2 | awk -F ' {2,}' '{print $1}')" -- "$cur"))
20+
_comp_compgen_split -l -- "$(nmcli dev wifi list 2>/dev/null |
21+
tail -n +2 | awk -F ' {2,}' '{print $1}')"
2422
}
2523

2624
_comp_cmd_nmcli__ap_bssid()
2725
{
28-
COMPREPLY=($(compgen -W "$(nmcli dev wifi list 2>/dev/null |
29-
tail -n +2 | awk -F ' {2,}' '{print $2}')" -- "$cur"))
26+
_comp_compgen_split -- "$(nmcli dev wifi list 2>/dev/null |
27+
tail -n +2 | awk -F ' {2,}' '{print $2}')"
3028
}
3129

3230
_comp_cmd_nmcli()

completions/_rfkill

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ _comp_cmd_rfkill()
1717
;;
1818
2)
1919
if [[ $prev == block || $prev == unblock ]]; then
20-
COMPREPLY=($(compgen -W "$("$1" list | awk -F: \
21-
'/^[0-9]/ {print $1}') all wifi bluetooth uwb wimax \
22-
wwan gps" -- "$cur"))
20+
_comp_compgen_split -- "$("$1" list |
21+
awk -F: '/^[0-9]/ {print $1}') all wifi bluetooth uwb
22+
wimax wwan gps"
2323
fi
2424
;;
2525
esac

completions/_udevadm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ _comp_cmd_udevadm()
5858
_comp_compgen -- -W '--help --version --debug'
5959
;;
6060
*)
61-
COMPREPLY=($(compgen -W "$("$1" --help 2>/dev/null |
62-
awk '/^[ \t]/ { print $1 }')" -- "$cur"))
61+
_comp_compgen_split -- "$("$1" --help 2>/dev/null |
62+
awk '/^[ \t]/ { print $1 }')"
6363
;;
6464
esac
6565
return

completions/_xm

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
_comp_cmd_xm__domain_names()
88
{
9-
COMPREPLY=($(compgen -W "$(xm list 2>/dev/null |
10-
awk '!/Name|Domain-0/ { print $1 }')" -- "$cur"))
9+
_comp_compgen_split -- "$(xm list 2>/dev/null |
10+
awk '!/Name|Domain-0/ { print $1 }')"
1111
}
1212

1313
_comp_cmd_xm()
@@ -146,9 +146,8 @@ _comp_cmd_xm()
146146
_comp_cmd_xm__domain_names
147147
;;
148148
3)
149-
COMPREPLY=($(compgen -W "$(xm block-list "$prev" \
150-
2>/dev/null | awk '!/Vdev/ { print $1 }')" \
151-
-- "$cur"))
149+
_comp_compgen_split -- "$(xm block-list "$prev" \
150+
2>/dev/null | awk '!/Vdev/ { print $1 }')"
152151
;;
153152
esac
154153
;;
@@ -171,9 +170,8 @@ _comp_cmd_xm()
171170
_comp_cmd_xm__domain_names
172171
;;
173172
3)
174-
COMPREPLY=($(compgen -W "$(xm network-list "$prev" \
175-
2>/dev/null | awk '!/Idx/ { print $1 }')" \
176-
-- "$cur"))
173+
_comp_compgen_split -- "$(xm network-list "$prev" \
174+
2>/dev/null | awk '!/Idx/ { print $1 }')"
177175
;;
178176
esac
179177
;;

0 commit comments

Comments
 (0)