Skip to content

Commit

Permalink
fix(_command_offset): receive index in COMP_WORDS through compat name
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Dec 17, 2022
1 parent 58cfb75 commit 25d5f8f
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -2390,14 +2390,33 @@ _comp_command_offset()
done
fi
}
_comp_deprecate_func _command_offset _comp_command_offset

# @deprecated Use "_comp_command_offset" instead. It should be noted that the
# new interface "_comp_command_offset" is changed to receive an index in
# "words" instead of that in "COMP_WORDS" as "_command_offset" did.
_command_offset()
{
# This compatibility function assumes the first argument to be the index in
# "COMP_WORDS" instead of that in "words". To tell it to the new interface
# "_comp_command_offset", we locally make the variable "words" in the unset
# state.
local words
unset -v words
_comp_command_offset "$@"
}

# A _comp_command_offset wrapper function for use when the offset is unknown.
# Only intended to be used as a completion function directly associated
# with a command, not to be invoked from within other completion functions.
#
_comp_command()
{
# We locally make the shell variable "words" in the unset state to tell
# "_comp_command_offset" that the index is intended to be that in
# "COMP_WORDS" instead of "words".
local words
unset -v words

local offset i

# find actual offset, as position of the first non-option
Expand Down

0 comments on commit 25d5f8f

Please sign in to comment.