Skip to content

Commit 5d49f24

Browse files
committed
fix: use "_comp_expand_glob" for failglob/nullglob/etc
1 parent 13464e4 commit 5d49f24

File tree

16 files changed

+83
-82
lines changed

16 files changed

+83
-82
lines changed

bash_completion

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,15 +1148,20 @@ _mac_addresses()
11481148
#
11491149
_configured_interfaces()
11501150
{
1151+
local -a files
11511152
if [[ -f /etc/debian_version ]]; then
11521153
# Debian system
1154+
_comp_expand_glob files '/etc/network/interfaces /etc/network/interfaces.d/*'
1155+
((${#files[@]})) || return 0
11531156
COMPREPLY=($(compgen -W "$(command sed -ne 's|^iface \([^ ]\{1,\}\).*$|\1|p' \
1154-
/etc/network/interfaces /etc/network/interfaces.d/* 2>/dev/null)" \
1157+
"${files[@]}" 2>/dev/null)" \
11551158
-- "$cur"))
11561159
elif [[ -f /etc/SuSE-release ]]; then
11571160
# SuSE system
1161+
_comp_expand_glob files '/etc/sysconfig/network/ifcfg-*'
1162+
((${#files[@]})) || return 0
11581163
COMPREPLY=($(compgen -W "$(printf '%s\n' \
1159-
/etc/sysconfig/network/ifcfg-* |
1164+
"${files[@]}" |
11601165
command sed -ne 's|.*ifcfg-\([^*].*\)$|\1|p')" -- "$cur"))
11611166
elif [[ -f /etc/pld-release ]]; then
11621167
# PLD Linux
@@ -1165,8 +1170,10 @@ _configured_interfaces()
11651170
command sed -ne 's|.*ifcfg-\([^*].*\)$|\1|p')" -- "$cur"))
11661171
else
11671172
# Assume Red Hat
1173+
_comp_expand_glob files '/etc/sysconfig/network-scripts/ifcfg-*'
1174+
((${#files[@]})) || return 0
11681175
COMPREPLY=($(compgen -W "$(printf '%s\n' \
1169-
/etc/sysconfig/network-scripts/ifcfg-* |
1176+
"${files[@]}" |
11701177
command sed -ne 's|.*ifcfg-\([^*].*\)$|\1|p')" -- "$cur"))
11711178
fi
11721179
}
@@ -1422,12 +1429,12 @@ _xinetd_services()
14221429
{
14231430
local xinetddir=${_comp__test_xinetd_dir:-/etc/xinetd.d}
14241431
if [[ -d $xinetddir ]]; then
1425-
local IFS=$' \t\n' reset=$(shopt -p nullglob)
1426-
shopt -s nullglob
1427-
local -a svcs=($xinetddir/!($_comp_backup_glob))
1428-
$reset
1429-
((!${#svcs[@]})) ||
1432+
local -a svcs
1433+
_comp_expand_glob svcs '$xinetddir/!($_comp_backup_glob)'
1434+
if ((${#svcs[@]})); then
1435+
local IFS=$'\n'
14301436
COMPREPLY+=($(compgen -W '"${svcs[@]#$xinetddir/}"' -- "${cur-}"))
1437+
fi
14311438
fi
14321439
}
14331440

@@ -1438,12 +1445,9 @@ _services()
14381445
local sysvdirs
14391446
_sysvdirs
14401447

1441-
local IFS=$' \t\n' reset=$(shopt -p nullglob)
1442-
shopt -s nullglob
1443-
COMPREPLY=(
1444-
$(printf '%s\n' ${sysvdirs[0]}/!($_comp_backup_glob|functions|README)))
1445-
$reset
1448+
_comp_expand_glob COMPREPLY '${sysvdirs[0]}/!($_comp_backup_glob|functions|README)'
14461449

1450+
local IFS=$'\n'
14471451
COMPREPLY+=($({
14481452
systemctl list-units --full --all ||
14491453
systemctl list-unit-files
@@ -1474,7 +1478,7 @@ _service()
14741478
_services
14751479
[[ -e /etc/mandrake-release ]] && _xinetd_services
14761480
else
1477-
local sysvdirs
1481+
local IFS=$'\n' sysvdirs
14781482
_sysvdirs
14791483
COMPREPLY=($(compgen -W '`command sed -e "y/|/ /" \
14801484
-ne "s/^.*\(U\|msg_u\)sage.*{\(.*\)}.*$/\2/p" \
@@ -1726,7 +1730,9 @@ _terms()
17261730
{
17271731
toe -a || toe
17281732
} | awk '{ print $1 }'
1729-
find /{etc,lib,usr/lib,usr/share}/terminfo/? -type f -maxdepth 1 |
1733+
_comp_expand_glob dirs '/{etc,lib,usr/lib,usr/share}/terminfo/?'
1734+
((${#dirs[@]})) &&
1735+
find "${dirs[@]}" -type f -maxdepth 1 |
17301736
awk -F/ '{ print $NF }'
17311737
} 2>/dev/null)" -- "$cur"))
17321738
}

completions/_rtcwake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ _rtcwake()
1717
return
1818
;;
1919
--device | -d)
20-
COMPREPLY=($(command ls -d /dev/rtc?* 2>/dev/null))
20+
_comp_expand_glob COMPREPLY '/dev/rtc?*'
2121
((${#COMPREPLY[@]})) &&
2222
COMPREPLY=($(compgen -W '"${COMPREPLY[@]#/dev/}"' -- "$cur"))
2323
return

completions/_yum

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ _yum_repolist()
3030

3131
_yum_plugins()
3232
{
33-
command ls /usr/lib/yum-plugins/*.py{,c,o} 2>/dev/null |
33+
local -a files
34+
_comp_expand_glob files '/usr/lib/yum-plugins/*.py{,c,o}'
35+
((${#files[@]})) &&
36+
printf '%s\n' "${files[@]}" |
3437
command sed -ne 's|.*/\([^./]*\)\.py[co]\{0,1\}$|\1|p' | sort -u
3538
}
3639

completions/dpkg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ _dpkg_reconfigure()
133133

134134
case $prev in
135135
--frontend | -!(-*)f)
136-
opt=(/usr/share/perl5/Debconf/FrontEnd/*)
136+
_comp_expand_glob opt '/usr/share/perl5/Debconf/FrontEnd/*'
137137
if ((${#opt[@]})); then
138138
opt=(${opt[@]##*/})
139139
opt=(${opt[@]%.pm})

completions/hcitool

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ _hciattach()
354354
_count_args
355355
case $args in
356356
1)
357-
COMPREPLY=(/dev/tty*)
357+
_comp_expand_glob COMPREPLY '/dev/tty*'
358358
((${#COMPREPLY[@]})) &&
359359
COMPREPLY=($(compgen -W '"${COMPREPLY[@]}"
360360
"${COMPREPLY[@]#/dev/}"' -- "$cur"))

completions/hunspell

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,12 @@ _hunspell()
1010
return
1111
;;
1212
-d)
13-
local IFS=$' \t\n' reset=$(shopt -p nullglob)
14-
shopt -s nullglob
15-
local -a dicts=(/usr/share/hunspell/*.dic
16-
/usr/local/share/hunspell/*.dic)
17-
$reset
13+
local -a dicts
14+
_comp_expand_glob dicts '/usr/share/hunspell/*.dic /usr/local/share/hunspell/*.dic'
1815
if ((${#dicts[@]})); then
1916
dicts=("${dicts[@]##*/}")
2017
dicts=("${dicts[@]%.dic}")
21-
IFS=$'\n'
18+
local IFS=$'\n'
2219
COMPREPLY=($(compgen -W '${dicts[@]}' -- "$cur"))
2320
fi
2421
return

completions/ipmitool

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ _ipmitool()
1616
return
1717
;;
1818
-*d)
19-
COMPREPLY=($(compgen -W "$(
20-
command ls -d /dev/ipmi* /dev/ipmi/* /dev/ipmidev/* \
21-
2>/dev/null | command sed -ne 's/^[^0-9]*\([0-9]\{1,\}\)/\1/p'
22-
)" \
23-
-- "$cur"))
19+
local -a files
20+
_comp_expand_glob files '/dev/ipmi* /dev/ipmi/* /dev/ipmidev/*'
21+
((${#files[@]})) &&
22+
COMPREPLY=($(compgen -W "$(
23+
printf '%s\n' "${files[@]}" |
24+
command sed -ne 's/^[^0-9]*\([0-9]\{1,\}\)/\1/p'
25+
)" \
26+
-- "$cur"))
2427
return
2528
;;
2629
-*I)

completions/lintian

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22

33
_lintian_tags()
44
{
5-
local match search tags
5+
local match search tags check_files
6+
_comp_expand_glob check_files '/usr/share/lintian/checks/*.desc'
7+
((${#check_files[@]})) || return 0
68

7-
tags=$(awk '/^Tag/ { print $2 }' /usr/share/lintian/checks/*.desc)
9+
tags=$(awk '/^Tag/ { print $2 }' "${check_files[@]}")
810
if [[ $cur == *, ]]; then
911
search=${cur//,/ }
1012
for item in $search; do
1113
match=$(command grep -nE "^Tag: $item$" \
12-
/usr/share/lintian/checks/*.desc | cut -d: -f1)
14+
"${check_files[@]}" | cut -d: -f1)
1315
tags=$(command sed -e "s/\<$item\>//g" <<<$tags)
1416
done
1517
COMPREPLY+=($(compgen -W "$tags"))
@@ -22,15 +24,17 @@ _lintian_tags()
2224

2325
_lintian_checks()
2426
{
25-
local match search todisable checks
27+
local match search todisable checks check_files
28+
_comp_expand_glob check_files '/usr/share/lintian/checks/*.desc'
29+
((${#check_files[@]})) || return 0
2630

2731
checks=$(awk '/^(Check-Script|Abbrev)/ { print $2 }' \
28-
/usr/share/lintian/checks/*.desc)
32+
"${check_files[@]}")
2933
if [[ $cur == *, ]]; then
3034
search=${cur//,/ }
3135
for item in $search; do
3236
match=$(command grep -nE "^(Check-Script|Abbrev): $item$" \
33-
/usr/share/lintian/checks/*.desc | cut -d: -f1)
37+
"${check_files[@]}" | cut -d: -f1)
3438
todisable=$(awk '/^(Check-Script|Abbrev)/ { print $2 }' $match)
3539
for name in $todisable; do
3640
checks=$(command sed -e "s/\<$name\>//g" <<<$checks)
@@ -46,15 +50,17 @@ _lintian_checks()
4650

4751
_lintian_infos()
4852
{
49-
local match search infos
53+
local match search infos collection_files
54+
_comp_expand_glob collection_files '/usr/share/lintian/collection/*.desc'
55+
((${#collection_files[@]})) || return 0
5056

5157
infos=$(awk '/^Collector/ { print $2 }' \
52-
/usr/share/lintian/collection/*.desc)
58+
"${collection_files[@]}")
5359
if [[ $cur == *, ]]; then
5460
search=${cur//,/ }
5561
for item in $search; do
5662
match=$(command grep -nE "^Collector: $item$" \
57-
/usr/share/lintian/collection/*.desc | cut -d: -f1)
63+
"${collection_files[@]}" | cut -d: -f1)
5864
infos=$(command sed -e "s/\<$item\>//g" <<<$infos)
5965
done
6066
COMPREPLY+=($(compgen -W "$infos"))

completions/minicom

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ _minicom()
1515
return
1616
;;
1717
--ptty | -!(-*)p)
18-
COMPREPLY=(/dev/tty*)
18+
_comp_expand_glob COMPREPLY '/dev/tty*'
1919
((${#COMPREPLY[@]})) &&
2020
COMPREPLY=($(compgen -W '"${COMPREPLY[@]}" "${COMPREPLY[@]#/dev/}}' \
2121
-- "$cur"))
@@ -31,10 +31,10 @@ _minicom()
3131
return
3232
fi
3333

34-
COMPREPLY=(
35-
$(printf '%s\n' /etc/minirc.* /etc/minicom/minirc.* ~/.minirc.* |
36-
command sed -e '/\*$/d' -e 's/^.*minirc\.//' |
37-
command grep "^${cur}"))
34+
local -a files
35+
_comp_expand_glob files '/etc/minirc.* /etc/minicom/minirc.* ~/.minirc.*'
36+
((${#files[@]})) &&
37+
COMPREPLY=($(compgen -W '"${files[@]##*minirc.}"' -- "$cur"))
3838
} &&
3939
complete -F _minicom -o default minicom
4040

completions/mysql

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
_comp_xfunc_mysql_character_sets()
44
{
5-
local IFS=$' \t\n' reset=$(shopt -p failglob)
6-
shopt -u failglob
7-
local -a charsets=(/usr/share/m{ariadb,ysql}/charsets/*.xml)
8-
$reset
5+
local -a charsets
6+
_comp_expand_glob charsets '/usr/share/m{ariadb,ysql}/charsets/*.xml'
97
if ((${#charsets[@]})); then
108
charsets=("${charsets[@]##*/}")
11-
charsets=("${charsets[@]%%?(Index|\*).xml}" utf8)
9+
charsets=("${charsets[@]%%?(Index).xml}" utf8)
10+
local IFS=$'\n'
1211
COMPREPLY+=($(compgen -W '${charsets[@]}' -- "$cur"))
1312
fi
1413
}

0 commit comments

Comments
 (0)