@@ -1136,8 +1136,8 @@ _comp__split_longopt()
11361136# Complete variables.
11371137# @return True (0) if variables were completed,
11381138# False (> 0) if not.
1139- # TODO:API: rename per conventions
1140- _variables ()
1139+ # @since 2.12
1140+ _comp_compgen_variables ()
11411141{
11421142 if [[ $cur =~ ^(\$ (\{ [! # ]?)?)([A-Za-z0-9_]*)$ ]]; then
11431143 # Completing $var / ${var / ${!var / ${#var
@@ -1148,10 +1148,10 @@ _variables()
11481148 if (( ${# vars[@]} == 1 && ${# arrs[@]} != 0 )) ; then
11491149 # Complete ${arr with ${array[ if there is only one match, and that match is an array variable
11501150 compopt -o nospace
1151- COMPREPLY+=( " ${arrs[@]} " )
1151+ _comp_compgen -U vars -U arrs -R -- -W ' "${arrs[@]}"'
11521152 else
11531153 # Complete ${var with ${variable}
1154- COMPREPLY+=( " ${vars[@]} " )
1154+ _comp_compgen -U vars -U arrs -R -- -W ' "${vars[@]}"'
11551155 fi
11561156 else
11571157 # Complete $var with $variable
@@ -1160,18 +1160,23 @@ _variables()
11601160 return 0
11611161 elif [[ $cur =~ ^(\$\{ [#! ]?)([A-Za-z0-9_]*)\[([^]]*)$ ]]; then
11621162 # Complete ${array[i with ${array[idx]}
1163- _comp_compgen -a c " ${BASH_REMATCH[3]} " -- -W ' "${!' " ${BASH_REMATCH[2]} " ' [@]}"' \
1163+ local vars
1164+ _comp_compgen -v vars -c " ${BASH_REMATCH[3]} " -- -W ' "${!' " ${BASH_REMATCH[2]} " ' [@]}"' \
11641165 -P " ${BASH_REMATCH[1]}${BASH_REMATCH[2]} [" -S ' ]}'
11651166 # Complete ${arr[@ and ${arr[*
11661167 if [[ ${BASH_REMATCH[3]} == [@* ] ]]; then
1167- COMPREPLY+=(" ${BASH_REMATCH[1]}${BASH_REMATCH[2]} [${BASH_REMATCH[3]} ]}" )
1168+ vars+=(" ${BASH_REMATCH[1]}${BASH_REMATCH[2]} [${BASH_REMATCH[3]} ]}" )
1169+ fi
1170+ # array indexes may have colons
1171+ if (( ${# vars[@]} )) ; then
1172+ _comp_compgen -U vars -c " $cur " ltrim_colon " ${vars[@]} "
1173+ else
1174+ _comp_compgen_set
11681175 fi
1169- _comp_ltrim_colon_completions " $cur " # array indexes may have colons
11701176 return 0
11711177 elif [[ $cur =~ ^\$\{ [#! ]?[A-Za-z0-9_]*\[.*\]$ ]]; then
11721178 # Complete ${array[idx] with ${array[idx]}
1173- COMPREPLY+= (" $cur }" )
1174- _comp_ltrim_colon_completions " $cur "
1179+ _comp_compgen -c " $cur " ltrim_colon " $cur }"
11751180 return 0
11761181 fi
11771182 return 1
@@ -1284,7 +1289,7 @@ _comp_variable_assignments()
12841289 _comp_delimited : -W ' $(locale -a 2>/dev/null)'
12851290 ;;
12861291 * )
1287- _variables && return 0
1292+ _comp_compgen_variables && return 0
12881293 _comp_compgen -a filedir
12891294 ;;
12901295 esac
@@ -1355,7 +1360,7 @@ _comp_initialize()
13551360 _comp_get_words -n " $exclude <>&" cur prev words cword
13561361
13571362 # Complete variable names.
1358- _variables && return 1
1363+ _comp_compgen_variables && return 1
13591364
13601365 # Complete on files if current is a redirect possibly followed by a
13611366 # filename, e.g. ">foo", or previous is a "bare" redirect, e.g. ">".
0 commit comments