No subject
Thu Aug 20 06:46:28 UTC 2009
Since the behaviour of COMP_WORDS has changed from bash3 to bash4
(COMP_WORDS is now split along COMP_WORDBREAKS, instead of along `shell
metacharacters'), there are times when the following common convention
produces an overlapping set:
local cur=`_get_cword`
local prev="${COMP_WORDS[COMP_CWORD-1]}"
This is especially true when _get_cword() is called with an optional
argument of exceptions to COMP_WORDBREAKS. For example:
$ command subcommand --user=root:toor:<TAB>
# in the completion function
local cur=`_get_cword =:`
local prev="${COMP_WORDS[COMP_CWORD-1]}"
bash3 returns:
cur: --user=root:toor:
prev: subcommand
while bash4 returns a less useful:
cur: --user=root:toor:
prev: toor
This patch extends both __get_cword3() and __get_cword4() to accept an
additional integer argument that specifies how many places previous to
the current word the desired word resides. It also respects any user
exceptions to COMP_WORDBREAKS.
_get_pword() is then implemented as a wrapper: `_get_cword "${@:-}" 1'
So:
local cur=`_get_cword =:` => --user=root:toor:
local prev=`_get_pword =:` => subcommand
produces the same results in bash3 and bash4.
----------------------------------------------------------------------
You can respond by visiting:
https://alioth.debian.org/tracker/?func=detail&atid=413095&aid=312030&group_id=100114
More information about the Bash-completion-devel
mailing list