On Sun, 20 Nov 2011 12:05:23 +0200
Ville Skyttä <[email protected]> wrote:
> >> # Note: intentionally using COMP_WORDS and COMP_CWORD instead of
> >> # words and cword here due to splitting on = causing index differences
> >
> > But using COMP_WORDS directly will brake for any argument, that contains
> > character from COMP_WORDBREAKS, for example for --log-socket=ipaddr:port.
>
> I don't see a sane and maintainable way to make this work with using
> words instead of COMP_WORDS.
I wrote the code for that purpose. It finds an offset for the $words array at
first and then translates found value to an offset for the $COMP_WORDS. Here it
is:
--------------------------------------
_valgrind()
{
local cur prev words cword
_init_completion -n :=\'\" || return
local offset i
offset=0
for (( i=1; i <= cword; i++ )); do
if [[ ${words[i]} != --* ]]; then
offset=$i
break
fi
done
if [[ $offset -gt 0 && $offset -lt $cword ]]; then
local j
local cowords=( "${COMP_WORDS[@]}" )
i=0; j=0
while [[ $i -lt $offset ]]; do
if [[ ${#words[i]} -lt ${#cowords[j]} ]]; then
cowords[j]=${cowords[j]#"${words[i]}"}
words[i]=
((i++))
[[ ${cowords[j]} ]] || ((j++))
else
words[i]=${words[i]#"${cowords[j]}"}
cowords[j]=
((j++))
[[ ${words[i]} ]] || ((i++))
fi
done
_command_offset $j
return
fi
--------------------------------------
Probably the better way to go is to make _command_offset() work with $words
rather then with $COMP_WORDS directly.
-- Igor
_______________________________________________
Bash-completion-devel mailing list
[email protected]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/bash-completion-devel