Skip to content

Commit c8ec2ca

Browse files
committed
fix(_comp_finalize): fix test errors
1 parent bc6f87d commit c8ec2ca

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

bash_completion

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -954,8 +954,11 @@ _comp_finalize()
954954
while ((${#FUNCNAME[@]} <= ${_comp_finalize__depth[-1]})); do
955955
if ((${#FUNCNAME[@]} == ${_comp_finalize__depth[-1]})); then
956956
# Call finalizer for each command
957-
local __comp_hook=${BASH_COMPLETION_FINALIZE_CMD_HOOKS[${words[0]-}]-}
958-
eval -- "$__comp_hook"
957+
local cmd=${words[0]-}
958+
if [[ $cmd ]]; then
959+
local __comp_hook=${BASH_COMPLETION_FINALIZE_CMD_HOOKS[$cmd]-}
960+
eval -- "$__comp_hook"
961+
fi
959962

960963
# Call general finalizers
961964
if ((${#BASH_COMPLETION_FINALIZE_HOOKS[@]})); then
@@ -997,25 +1000,27 @@ _init_completion()
9971000
{
9981001
local exclude="" flag outx errx inx OPTIND=1
9991002

1000-
# Install "_comp_finalize" to the RETURN trap when "_init_completion" is
1001-
# called for the top-level completion. [ Note: the completion function may
1002-
# be called recursively using "_command_offset", etc. ]
1003-
if ((${#_comp_finalize__depth[@]} == 0)); then
1004-
if shopt -q extdebug || shopt -qo functrace; then
1005-
# If extdebug / functrace is set, we need to explicitly save and
1006-
# restore the original trap handler because the outer trap handlers
1007-
# will be affected by "trap - RETURN" inside functions with these
1008-
# settings.
1009-
_comp_finalize__original_return_trap=$(trap -p RETURN)
1010-
else
1011-
# Otherwise, the outer RETURN trap will be restored when the RETURN
1012-
# trap is removed inside the functions using "trap - RETURN". So, we
1013-
# do not need to explicitly save the outer trap handler.
1014-
_comp_finalize__original_return_trap=
1003+
if ((${#FUNCNAME[@]} >= 2)); then
1004+
# Install "_comp_finalize" to the RETURN trap when "_init_completion" is
1005+
# called for the top-level completion. [ Note: the completion function may
1006+
# be called recursively using "_command_offset", etc. ]
1007+
if ((${#_comp_finalize__depth[@]} == 0)); then
1008+
if shopt -q extdebug || shopt -qo functrace; then
1009+
# If extdebug / functrace is set, we need to explicitly save and
1010+
# restore the original trap handler because the outer trap handlers
1011+
# will be affected by "trap - RETURN" inside functions with these
1012+
# settings.
1013+
_comp_finalize__original_return_trap=$(trap -p RETURN)
1014+
else
1015+
# Otherwise, the outer RETURN trap will be restored when the RETURN
1016+
# trap is removed inside the functions using "trap - RETURN". So, we
1017+
# do not need to explicitly save the outer trap handler.
1018+
_comp_finalize__original_return_trap=
1019+
fi
1020+
trap _comp_finalize RETURN
10151021
fi
1016-
trap _comp_finalize RETURN
1022+
_comp_finalize__depth+=(${#FUNCNAME[@]})
10171023
fi
1018-
_comp_finalize__depth+=(${#FUNCNAME[@]})
10191024

10201025
while getopts "n:e:o:i:s" flag "$@"; do
10211026
case $flag in

0 commit comments

Comments
 (0)