@@ -396,8 +396,7 @@ _comp_looks_like_path()
396
396
#
397
397
__reassemble_comp_words_by_ref ()
398
398
{
399
- local exclude i j line ref
400
- unset -v exclude # workaround for localvar_inherit
399
+ local exclude=" " i j line ref
401
400
# Exclude word separator characters?
402
401
if [[ $1 ]]; then
403
402
# Yes, exclude word separator characters;
@@ -408,7 +407,7 @@ __reassemble_comp_words_by_ref()
408
407
# Default to cword unchanged
409
408
printf -v " $3 " %s " $COMP_CWORD "
410
409
# Are characters excluded which were former included?
411
- if [[ -v exclude ]]; then
410
+ if [[ $ exclude ]]; then
412
411
# Yes, list of word completion separators has shrunk;
413
412
line=$COMP_LINE
414
413
# Re-assemble words to complete
@@ -532,13 +531,18 @@ __get_cword_at_cursor_by_ref()
532
531
#
533
532
_get_comp_words_by_ref ()
534
533
{
535
- local exclude flag i OPTIND=1
534
+ local exclude= " " flag i OPTIND=1
536
535
local cur cword words=()
537
- local upargs=() upvars=() vcur vcword vprev vwords
538
- unset -v vcur vcword vprev vwords # workaround for localvar_inherit
536
+ local upargs=() upvars=() vcur=" " vcword=" " vprev=" " vwords=" "
539
537
540
538
while getopts " c:i:n:p:w:" flag " $@ " ; do
541
539
case $flag in
540
+ [cipw])
541
+ if [[ $OPTARG != [a-zA-Z_]* ([a-zA-Z_0-9])? (\[ * \] ) ]]; then
542
+ echo " bash_completion: $FUNCNAME : -$flag : invalid variable name \` $OPTARG '" >&2
543
+ return 1
544
+ fi
545
+ ;;&
542
546
c) vcur=$OPTARG ;;
543
547
i) vcword=$OPTARG ;;
544
548
n) exclude=$OPTARG ;;
@@ -567,19 +571,19 @@ _get_comp_words_by_ref()
567
571
568
572
__get_cword_at_cursor_by_ref " ${exclude-} " words cword cur
569
573
570
- [[ -v vcur ]] && {
574
+ [[ $ vcur ]] && {
571
575
upvars+=(" $vcur " )
572
576
upargs+=(-v $vcur " $cur " )
573
577
}
574
- [[ -v vcword ]] && {
578
+ [[ $ vcword ]] && {
575
579
upvars+=(" $vcword " )
576
580
upargs+=(-v $vcword " $cword " )
577
581
}
578
- [[ -v vprev && $cword -ge 1 ]] && {
582
+ [[ $ vprev && $cword -ge 1 ]] && {
579
583
upvars+=(" $vprev " )
580
584
upargs+=(-v $vprev " ${words[cword - 1]} " )
581
585
}
582
- [[ -v vwords ]] && {
586
+ [[ $ vwords ]] && {
583
587
upvars+=(" $vwords " )
584
588
upargs+=(-a${# words[@]} $vwords ${words+" ${words[@]} " } )
585
589
}
@@ -1883,10 +1887,9 @@ _included_ssh_config_files()
1883
1887
# @return Completions, starting with CWORD, are added to COMPREPLY[]
1884
1888
_known_hosts_real ()
1885
1889
{
1886
- local configfile flag prefix=" "
1887
- local cur suffix=" " aliases i host ipv4 ipv6
1890
+ local configfile= " " flag prefix=" "
1891
+ local cur suffix=" " aliases= " " i host ipv4= " " ipv6= " "
1888
1892
local -a kh tmpkh=() khd=() config=()
1889
- unset -v configfile aliases ipv4 ipv6 # workaround for localvar_inherit
1890
1893
1891
1894
# TODO remove trailing %foo from entries
1892
1895
@@ -1895,7 +1898,13 @@ _known_hosts_real()
1895
1898
case $flag in
1896
1899
a) aliases=' yes' ;;
1897
1900
c) suffix=' :' ;;
1898
- F) configfile=$OPTARG ;;
1901
+ F)
1902
+ if [[ ! $OPTARG ]]; then
1903
+ echo " bash_completion: $FUNCNAME : -F: an empty filename is specified" >&2
1904
+ return 1
1905
+ fi
1906
+ configfile=$OPTARG
1907
+ ;;
1899
1908
p) prefix=$OPTARG ;;
1900
1909
4) ipv4=1 ;;
1901
1910
6) ipv6=1 ;;
@@ -1924,7 +1933,7 @@ _known_hosts_real()
1924
1933
kh=()
1925
1934
1926
1935
# ssh config files
1927
- if [[ -v configfile ]]; then
1936
+ if [[ $ configfile ]]; then
1928
1937
[[ -r $configfile && ! -d $configfile ]] && config+=(" $configfile " )
1929
1938
else
1930
1939
for i in /etc/ssh/ssh_config ~ /.ssh/config ~ /.ssh2/config; do
@@ -1970,7 +1979,7 @@ _known_hosts_real()
1970
1979
done
1971
1980
fi
1972
1981
1973
- if [[ ! -v configfile ]]; then
1982
+ if [[ ! $ configfile ]]; then
1974
1983
# Global and user known_hosts files
1975
1984
for i in /etc/ssh/ssh_known_hosts /etc/ssh/ssh_known_hosts2 \
1976
1985
/etc/known_hosts /etc/known_hosts2 ~ /.ssh/known_hosts \
@@ -2035,7 +2044,7 @@ _known_hosts_real()
2035
2044
fi
2036
2045
2037
2046
# append any available aliases from ssh config files
2038
- if [[ ${# config[@]} -gt 0 && -v aliases ]]; then
2047
+ if [[ ${# config[@]} -gt 0 && $ aliases ]]; then
2039
2048
local -a hosts=($( command sed -ne ' s/^[[:blank:]]*[Hh][Oo][Ss][Tt][[:blank:]=]\{1,\}\(.*\)$/\1/p' " ${config[@]} " ) )
2040
2049
if (( ${# hosts[@]} != 0 )) ; then
2041
2050
COMPREPLY+=($( compgen -P " $prefix " \
@@ -2071,13 +2080,13 @@ _known_hosts_real()
2071
2080
$reset
2072
2081
2073
2082
if (( ${# COMPREPLY[@]} )) ; then
2074
- if [[ -v ipv4 ]]; then
2083
+ if [[ $ ipv4 ]]; then
2075
2084
COMPREPLY=(" ${COMPREPLY[@]/*:* $suffix / } " )
2076
2085
fi
2077
- if [[ -v ipv6 ]]; then
2086
+ if [[ $ ipv6 ]]; then
2078
2087
COMPREPLY=(" ${COMPREPLY[@]/ +([0-9]).+([0-9]).+([0-9]).+([0-9])$suffix / } " )
2079
2088
fi
2080
- if [[ -v ipv4 || -v ipv6 ]]; then
2089
+ if [[ $ ipv4 || $ ipv6 ]]; then
2081
2090
for i in " ${! COMPREPLY[@]} " ; do
2082
2091
[[ ${COMPREPLY[i]} ]] || unset -v ' COMPREPLY[i]'
2083
2092
done
0 commit comments