[Bash-completion-devel] Get stuck
Raph
gibboris at gmail.com
Mon May 23 20:57:14 UTC 2011
On Mon, May 23, 2011 at 11:39:45PM +0300, Ville Skyttä wrote:
> On 05/23/2011 02:45 AM, Igor Murzov wrote:
> > Hey! I get stuck trying to implement completion script for strings containing
> > two parts for completion delimited by '%' sign. For example, `cmd opt%arg`.
> > The problem is that, if i hit tab key, when cursor is behind delimeter, bash
> > eats first part of string leaving `cmd arg`.
> [...]
> > if [[ "$cur" == ?*%* ]]; then
> > cur="${cur#*%}"
> > COMPREPLY=( $( compgen -W 'abc bbb cde' -- "$cur" ) )
> > return 0
> > fi
>
> Not sure if I understand correctly, but does replacing the above with
> this work the way you'd like?
>
> if [[ "$cur" == ?*%* ]]; then
> COMPREPLY=( $( compgen -P "${cur%%%*}%" \
> -W 'abc bbb cde' -- "${cur#*%}" ) )
> return 0
> fi
I just tested the following, it works as it should (with the -P):
pref="${cur%\%*}"%
suf="${cur##*%}"
COMPREPLY=( $( compgen -P "${pref}" -W "abc bbb cde" -- "$suf" )
but I guess he would like the "other way"...
and I'm interested too in knowing how to deals with COMP_WORDBREAK,
(especially using properly the API)
Raph
More information about the Bash-completion-devel
mailing list