Skip to content

Commit c898bdb

Browse files
committed
fix(_comp_compgen): improve argument check
We allow positional parameters ($1...) in the current word specified as `-- CUR` at the end of the argument list.
1 parent 6981c03 commit c898bdb

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

bash_completion

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,14 @@ _comp_compgen()
432432
elif [[ $1 == @(*[^_a-zA-Z0-9]*|[0-9]*|''|_*|IFS|OPTIND|OPTARG|OPTERR) ]]; then
433433
printf '%s\n' "bash_completion: $FUNCNAME: invalid array name \`$1'." >&2
434434
return 2
435-
elif [[ ${*:2} == *\$[0-9]* || ${*:2} == *\$\{[0-9]* ]]; then
435+
elif
436+
local _nopt=$(($# - 1))
437+
[[ ${*:$#-1:1} == -- ]] && ((_nopt -= 2)) # exclude "-- CUR" from check
438+
[[ ${*:2:_nopt} == *\$[0-9]* || ${*:2:_nopt} == *\$\{[0-9]* ]]
439+
then
436440
# Note: extglob *\$?(\{)[0-9]* can be extremely slow when the string
437-
# "${*:2}" becomes longer, so we test \$[0-9] and \$\{[0-9] separately.
441+
# "${*:2:_nopt}" becomes longer, so we test \$[0-9] and \$\{[0-9]
442+
# separately.
438443
printf '%s\n' "bash_completion: $FUNCNAME: positional parameter \$1, \$2, ... do not work inside this function." >&2
439444
return 2
440445
fi

0 commit comments

Comments
 (0)