@@ -1137,8 +1137,8 @@ _comp__split_longopt()
11371137# Complete variables.
11381138# @return True (0) if variables were completed,
11391139# False (> 0) if not.
1140- # TODO:API: rename per conventions
1141- _variables ()
1140+ # @since 2.12
1141+ _comp_compgen_variables ()
11421142{
11431143 if [[ $cur =~ ^(\$ (\{ [! # ]?)?)([A-Za-z0-9_]*)$ ]]; then
11441144 # Completing $var / ${var / ${!var / ${#var
@@ -1149,10 +1149,10 @@ _variables()
11491149 if (( ${# vars[@]} == 1 && ${# arrs[@]} != 0 )) ; then
11501150 # Complete ${arr with ${array[ if there is only one match, and that match is an array variable
11511151 compopt -o nospace
1152- COMPREPLY+=( " ${arrs[@]} " )
1152+ _comp_compgen -U vars -U arrs -R -- -W ' "${arrs[@]}"'
11531153 else
11541154 # Complete ${var with ${variable}
1155- COMPREPLY+=( " ${vars[@]} " )
1155+ _comp_compgen -U vars -U arrs -R -- -W ' "${vars[@]}"'
11561156 fi
11571157 else
11581158 # Complete $var with $variable
@@ -1161,18 +1161,23 @@ _variables()
11611161 return 0
11621162 elif [[ $cur =~ ^(\$\{ [#! ]?)([A-Za-z0-9_]*)\[([^]]*)$ ]]; then
11631163 # Complete ${array[i with ${array[idx]}
1164- _comp_compgen -a c " ${BASH_REMATCH[3]} " -- -W ' "${!' " ${BASH_REMATCH[2]} " ' [@]}"' \
1164+ local vars
1165+ _comp_compgen -v vars -c " ${BASH_REMATCH[3]} " -- -W ' "${!' " ${BASH_REMATCH[2]} " ' [@]}"' \
11651166 -P " ${BASH_REMATCH[1]}${BASH_REMATCH[2]} [" -S ' ]}'
11661167 # Complete ${arr[@ and ${arr[*
11671168 if [[ ${BASH_REMATCH[3]} == [@* ] ]]; then
1168- COMPREPLY+=(" ${BASH_REMATCH[1]}${BASH_REMATCH[2]} [${BASH_REMATCH[3]} ]}" )
1169+ vars+=(" ${BASH_REMATCH[1]}${BASH_REMATCH[2]} [${BASH_REMATCH[3]} ]}" )
1170+ fi
1171+ # array indexes may have colons
1172+ if (( ${# vars[@]} )) ; then
1173+ _comp_compgen -U vars -c " $cur " ltrim_colon " ${vars[@]} "
1174+ else
1175+ _comp_compgen_set
11691176 fi
1170- _comp_ltrim_colon_completions " $cur " # array indexes may have colons
11711177 return 0
11721178 elif [[ $cur =~ ^\$\{ [#! ]?[A-Za-z0-9_]*\[.*\]$ ]]; then
11731179 # Complete ${array[idx] with ${array[idx]}
1174- COMPREPLY+= (" $cur }" )
1175- _comp_ltrim_colon_completions " $cur "
1180+ _comp_compgen -c " $cur " ltrim_colon " $cur }"
11761181 return 0
11771182 fi
11781183 return 1
@@ -1285,7 +1290,7 @@ _comp_variable_assignments()
12851290 _comp_delimited : -W ' $(locale -a 2>/dev/null)'
12861291 ;;
12871292 * )
1288- _variables && return 0
1293+ _comp_compgen_variables && return 0
12891294 _comp_compgen -a filedir
12901295 ;;
12911296 esac
@@ -1356,7 +1361,7 @@ _comp_initialize()
13561361 _comp_get_words -n " $exclude <>&" cur prev words cword
13571362
13581363 # Complete variable names.
1359- _variables && return 1
1364+ _comp_compgen_variables && return 1
13601365
13611366 # Complete on files if current is a redirect possibly followed by a
13621367 # filename, e.g. ">foo", or previous is a "bare" redirect, e.g. ">".
0 commit comments