Bugs item #312030, was opened at 2009-10-26 09:00 by Sung Pae
You can respond by visiting: 
https://alioth.debian.org/tracker/?func=detail&atid=413095&aid=312030&group_id=100114

Status: Open
Priority: 3
Submitted By: Sung Pae (guns-guest)
Assigned to: Nobody (None)
Summary: [PATCH] Implementation of _get_pword() as a replacement for 
${COMP_WORDS[COMP_CWORD-1]} 
Distribution: None
Originally reported in: None
Milestone: None
Status: None
Original bug number: 


Initial Comment:
A workaround for surprising behaviour in bash4's handling of COMP_WORDS,
wrt getting the previous word in a completion.

So far it works as a drop in replacement for ${COMP_WORDS[COMP_CWORD-1]}.

>From the patch header:

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

_______________________________________________
Bash-completion-devel mailing list
[email protected]
http://lists.alioth.debian.org/mailman/listinfo/bash-completion-devel

Reply via email to