@@ -61,6 +61,36 @@ _comp_deprecate_func()
61
61
eval -- " $2 () { $3 \"\$ @\" ; }"
62
62
}
63
63
64
+ # Declare a compatibility variable name.
65
+ # For bash 4.3+, a real name alias is created, allowing value changes to
66
+ # "apply through" when the variables are set later. For bash versions earlier
67
+ # than that, the operation is once-only; the value of the new variable
68
+ # (if it's unset) is set to that of the old (if set) at call time.
69
+ #
70
+ # @param $1 Version of bash-completion where the deprecation occurred
71
+ # @param $2 Old variable name
72
+ # @param $3 New variable name
73
+ # @since 2.12
74
+ _comp_deprecate_var ()
75
+ {
76
+ if (( $# != 3 )) ; then
77
+ printf ' bash_completion: %s: usage: %s DEPRECATION_VERSION OLD_NAME NEW_NAME\n' " $FUNCNAME " " $FUNCNAME "
78
+ return 2
79
+ fi
80
+ if [[ $2 != [a-zA-Z_]* ([a-zA-Z_0-9]) ]]; then
81
+ printf ' bash_completion: %s: %s\n' " $FUNCNAME " " \$ 2: invalid variable name '$1 '" >&2
82
+ return 2
83
+ elif [[ $3 != [a-zA-Z_]* ([a-zA-Z_0-9]) ]]; then
84
+ printf ' bash_completion: %s: %s\n' " $FUNCNAME " " \$ 3: invalid variable name '$2 '" >&2
85
+ return 2
86
+ fi
87
+ if (( BASH_VERSINFO[0 ] >= 5 || BASH_VERSINFO[0 ] == 4 && BASH_VERSINFO[1 ] >= 3 )) ; then
88
+ eval " declare -gn $2 =$3 "
89
+ elif [[ -v $2 && ! -v $3 ]]; then
90
+ printf -v " $3 " %s " $2 "
91
+ fi
92
+ }
93
+
64
94
# A lot of the following one-liners were taken directly from the
65
95
# completion examples provided with the bash 2.04 source distribution
66
96
@@ -1092,14 +1122,13 @@ _comp_compgen_filedir()
1092
1122
# the fallback condition with the "plus" dirs.
1093
1123
local _opts=(-f -X " $_xspec " )
1094
1124
[[ $_xspec ]] && _plusdirs=(-o plusdirs)
1095
- [[ ${BASH_COMPLETION_FILEDIR_FALLBACK-${COMP_FILEDIR_FALLBACK-} } ||
1096
- ! ${_plusdirs-} ]] ||
1125
+ [[ ${BASH_COMPLETION_FILEDIR_FALLBACK-} || ! ${_plusdirs-} ]] ||
1097
1126
_opts+=(" ${_plusdirs[@]} " )
1098
1127
1099
1128
_comp_compgen -v toks -c " $_quoted " -- " ${_opts[@]} "
1100
1129
1101
1130
# Try without filter if it failed to produce anything and configured to
1102
- [[ ${BASH_COMPLETION_FILEDIR_FALLBACK-${COMP_FILEDIR_FALLBACK-} } &&
1131
+ [[ ${BASH_COMPLETION_FILEDIR_FALLBACK-} &&
1103
1132
$_arg && ${# toks[@]} -lt 1 ]] &&
1104
1133
_comp_compgen -av toks -c " $_quoted " -- \
1105
1134
-f ${_plusdirs+" ${_plusdirs[@]} " }
@@ -2626,7 +2655,7 @@ _comp_compgen_known_hosts__impl()
2626
2655
fi
2627
2656
2628
2657
# Add hosts reported by avahi-browse, if desired and it's available.
2629
- if [[ ${BASH_COMPLETION_KNOWN_HOSTS_WITH_AVAHI-${COMP_KNOWN_HOSTS_WITH_AVAHI-} } ]] &&
2658
+ if [[ ${BASH_COMPLETION_KNOWN_HOSTS_WITH_AVAHI-} ]] &&
2630
2659
type avahi-browse & > /dev/null; then
2631
2660
# Some old versions of avahi-browse reportedly didn't have -k
2632
2661
# (even if mentioned in the manpage); those we do not support any more.
@@ -2644,7 +2673,7 @@ _comp_compgen_known_hosts__impl()
2644
2673
2645
2674
# Add results of normal hostname completion, unless
2646
2675
# `BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE' is set to an empty value.
2647
- if [[ ${BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE-${COMP_KNOWN_HOSTS_WITH_HOSTFILE-1} } ]]; then
2676
+ if [[ ${BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE-set } ]]; then
2648
2677
_comp_compgen -av known_hosts -- -A hostname -P " $prefix " -S " $suffix "
2649
2678
fi
2650
2679
@@ -3006,8 +3035,7 @@ _comp_compgen_filedir_xspec()
3006
3035
_comp_compgen -av toks -c " $quoted " -- -f -X " @ (|! ($xspec ))"
3007
3036
3008
3037
# Try without filter if it failed to produce anything and configured to
3009
- [[ ${BASH_COMPLETION_FILEDIR_FALLBACK-${COMP_FILEDIR_FALLBACK-} } &&
3010
- ${# toks[@]} -lt 1 ]] &&
3038
+ [[ ${BASH_COMPLETION_FILEDIR_FALLBACK-} && ${# toks[@]} -lt 1 ]] &&
3011
3039
_comp_compgen -av toks -c " $quoted " -- -f
3012
3040
3013
3041
((${# toks[@]} )) || return 1
0 commit comments