@@ -149,6 +149,23 @@ dequote()
149
149
eval printf %s " $1 " 2> /dev/null
150
150
}
151
151
152
+ # Unset the given variables across a scope boundary. Useful for unshadowing
153
+ # global scoped variables. Note that simply calling unset on a local variable
154
+ # will not unshadow the global variable. Rather, the result will be a local
155
+ # variable in an unset state.
156
+ # Usage: local IFS='|'; _comp_unlocal IFS
157
+ # Param: $* Variable names to be unset
158
+ _comp_unlocal ()
159
+ {
160
+ if (( BASH_VERSINFO[0 ] >= 5 )) && shopt -q localvar_unset; then
161
+ shopt -u localvar_unset
162
+ unset -v " $@ "
163
+ shopt -s localvar_unset
164
+ else
165
+ unset -v " $@ "
166
+ fi
167
+ }
168
+
152
169
# Assign variable one scope above the caller
153
170
# Usage: local "$1" && _upvar $1 "value(s)"
154
171
# Param: $1 Variable name to assign value to
@@ -721,12 +738,12 @@ _comp_delimited()
721
738
# glob char escaping issues to deal with. Do removals by hand instead.
722
739
COMPREPLY=($( compgen " $@ " ) )
723
740
local -a existing
724
- local x i ifs= $IFS IFS=$delimiter
741
+ local x i IFS=$delimiter
725
742
existing=($cur )
726
743
# Do not remove the last from existing if it's not followed by the
727
744
# delimiter so we get space appended.
728
745
[[ ! $cur || $cur == * " $delimiter " ]] || unset -v " existing[${# existing[@]} -1]"
729
- IFS= $ifs
746
+ _comp_unlocal IFS
730
747
if (( ${# COMPREPLY[@]} )) ; then
731
748
for x in ${existing+" ${existing[@]} " } ; do
732
749
for i in " ${! COMPREPLY[@]} " ; do
@@ -1253,14 +1270,13 @@ else
1253
1270
if [[ ${1-} == -s ]]; then
1254
1271
procs=($( command ps ax -o comm | command sed -e 1d) )
1255
1272
else
1256
- local line i=-1 ifs=$IFS
1257
- IFS=$' \n '
1273
+ local line i=-1 IFS=$' \n '
1258
1274
# Some versions of ps don't support "command", but do "comm", e.g.
1259
1275
# some busybox ones. Fall back
1260
1276
local -a psout=($( {
1261
1277
command ps ax -o command= || command ps ax -o comm=
1262
1278
} 2> /dev/null) )
1263
- IFS= $ifs
1279
+ _comp_unlocal IFS
1264
1280
for line in " ${psout[@]} " ; do
1265
1281
if (( i == - 1 )) ; then
1266
1282
# First line, see if it has COMMAND column header. For
@@ -1751,7 +1767,7 @@ _included_ssh_config_files()
1751
1767
# Return: Completions, starting with CWORD, are added to COMPREPLY[]
1752
1768
_known_hosts_real ()
1753
1769
{
1754
- local configfile flag prefix=" " ifs= $IFS
1770
+ local configfile flag prefix=" "
1755
1771
local cur suffix=" " aliases i host ipv4 ipv6
1756
1772
local -a kh tmpkh=() khd=() config=()
1757
1773
@@ -1817,7 +1833,7 @@ _known_hosts_real()
1817
1833
# spaces in their name work (watch out for ~ expansion
1818
1834
# breakage! Alioth#311595)
1819
1835
tmpkh=($( awk ' sub("^[ \t]*([Gg][Ll][Oo][Bb][Aa][Ll]|[Uu][Ss][Ee][Rr])[Kk][Nn][Oo][Ww][Nn][Hh][Oo][Ss][Tt][Ss][Ff][Ii][Ll][Ee][ \t=]+", "") { print $0 }' " ${config[@]} " | sort -u) )
1820
- IFS= $ifs
1836
+ _comp_unlocal IFS
1821
1837
fi
1822
1838
if (( ${# tmpkh[@]} != 0 )) ; then
1823
1839
local j
@@ -1873,7 +1889,7 @@ _known_hosts_real()
1873
1889
# Add host to candidates
1874
1890
COMPREPLY+=($host )
1875
1891
done
1876
- IFS= $ifs
1892
+ _comp_unlocal IFS
1877
1893
done < " $i "
1878
1894
done
1879
1895
(( ${# COMPREPLY[@]} )) &&
@@ -1935,7 +1951,6 @@ _known_hosts_real()
1935
1951
$( compgen -A hostname -P " $prefix " -S " $suffix " -- " $cur " ) )
1936
1952
fi
1937
1953
1938
- IFS=$' \t\n '
1939
1954
$reset
1940
1955
1941
1956
if (( ${# COMPREPLY[@]} )) ; then
@@ -2349,12 +2364,12 @@ complete -F _minimal ''
2349
2364
__load_completion()
2350
2365
{
2351
2366
local -a dirs=(${BASH_COMPLETION_USER_DIR:- ${XDG_DATA_HOME:- $HOME / .local/ share} / bash-completion} /completions)
2352
- local ifs= $IFS IFS=: dir cmd=" ${1##*/ } " compfile
2367
+ local IFS=: dir cmd=" ${1##*/ } " compfile
2353
2368
[[ -n $cmd ]] || return 1
2354
2369
for dir in ${XDG_DATA_DIRS:-/ usr/ local/ share:/ usr/ share} ; do
2355
2370
dirs+=($dir /bash-completion/completions)
2356
2371
done
2357
- IFS= $ifs
2372
+ _comp_unlocal IFS
2358
2373
2359
2374
if [[ $BASH_SOURCE == */* ]]; then
2360
2375
dirs+=(" ${BASH_SOURCE%/* } /completions" )
0 commit comments