_command_offset: Do not assume that first word is unique in completion line.

This commit is contained in:
Igor Murzov 2011-11-15 03:37:01 +03:00
parent 87d31eb85d
commit 6843989baf

View File

@ -1607,16 +1607,16 @@ _command_offset()
# find new first word position, then # find new first word position, then
# rewrite COMP_LINE and adjust COMP_POINT # rewrite COMP_LINE and adjust COMP_POINT
local word_offset=$1 local word_offset=$1 i j
local first_word=${COMP_WORDS[$word_offset]} char_offset i for (( i=0; i < $word_offset; i++ )); do
for (( i=0; i <= ${#COMP_LINE}; i++ )); do for (( j=0; j <= ${#COMP_LINE}; j++ )); do
if [[ "${COMP_LINE:$i:${#first_word}}" == "$first_word" ]]; then [[ $COMP_LINE == ${COMP_WORDS[i]}* ]] && break
char_offset=$i COMP_LINE=${COMP_LINE:1}
break ((COMP_POINT--))
fi done
COMP_LINE=${COMP_LINE#"${COMP_WORDS[i]}"}
((COMP_POINT-=${#COMP_WORDS[i]}))
done done
COMP_LINE=${COMP_LINE:$char_offset}
COMP_POINT=$(( COMP_POINT - $char_offset ))
# shift COMP_WORDS elements and adjust COMP_CWORD # shift COMP_WORDS elements and adjust COMP_CWORD
for (( i=0; i <= COMP_CWORD - $word_offset; i++ )); do for (( i=0; i <= COMP_CWORD - $word_offset; i++ )); do