Skip to content

Commit

Permalink
fix(_comp_finalize): fix test errors
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Apr 12, 2022
1 parent bc6f87d commit c8ec2ca
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -954,8 +954,11 @@ _comp_finalize()
while ((${#FUNCNAME[@]} <= ${_comp_finalize__depth[-1]})); do
if ((${#FUNCNAME[@]} == ${_comp_finalize__depth[-1]})); then
# Call finalizer for each command
local __comp_hook=${BASH_COMPLETION_FINALIZE_CMD_HOOKS[${words[0]-}]-}
eval -- "$__comp_hook"
local cmd=${words[0]-}
if [[ $cmd ]]; then
local __comp_hook=${BASH_COMPLETION_FINALIZE_CMD_HOOKS[$cmd]-}
eval -- "$__comp_hook"
fi

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

# Install "_comp_finalize" to the RETURN trap when "_init_completion" is
# called for the top-level completion. [ Note: the completion function may
# be called recursively using "_command_offset", etc. ]
if ((${#_comp_finalize__depth[@]} == 0)); then
if shopt -q extdebug || shopt -qo functrace; then
# If extdebug / functrace is set, we need to explicitly save and
# restore the original trap handler because the outer trap handlers
# will be affected by "trap - RETURN" inside functions with these
# settings.
_comp_finalize__original_return_trap=$(trap -p RETURN)
else
# Otherwise, the outer RETURN trap will be restored when the RETURN
# trap is removed inside the functions using "trap - RETURN". So, we
# do not need to explicitly save the outer trap handler.
_comp_finalize__original_return_trap=
if ((${#FUNCNAME[@]} >= 2)); then
# Install "_comp_finalize" to the RETURN trap when "_init_completion" is
# called for the top-level completion. [ Note: the completion function may
# be called recursively using "_command_offset", etc. ]
if ((${#_comp_finalize__depth[@]} == 0)); then
if shopt -q extdebug || shopt -qo functrace; then
# If extdebug / functrace is set, we need to explicitly save and
# restore the original trap handler because the outer trap handlers
# will be affected by "trap - RETURN" inside functions with these
# settings.
_comp_finalize__original_return_trap=$(trap -p RETURN)
else
# Otherwise, the outer RETURN trap will be restored when the RETURN
# trap is removed inside the functions using "trap - RETURN". So, we
# do not need to explicitly save the outer trap handler.
_comp_finalize__original_return_trap=
fi
trap _comp_finalize RETURN
fi
trap _comp_finalize RETURN
_comp_finalize__depth+=(${#FUNCNAME[@]})
fi
_comp_finalize__depth+=(${#FUNCNAME[@]})

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

0 comments on commit c8ec2ca

Please sign in to comment.