diff options
author | Igor Murzov <e-mail@date.by> | 2011-11-15 03:37:01 +0300 |
---|---|---|
committer | Igor Murzov <e-mail@date.by> | 2011-11-15 03:37:01 +0300 |
commit | 6843989baf47e80218d89ee86b7f699c90e73be0 (patch) | |
tree | 996613891d8928c224dd1ab2ddf2e4993741cb18 | |
parent | 87d31eb85d5f3d4f603dccc9d9afe8853457d4fa (diff) | |
download | bash-completion-6843989baf47e80218d89ee86b7f699c90e73be0.tar.gz |
_command_offset: Do not assume that first word is unique in completion line.
-rw-r--r-- | bash_completion | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/bash_completion b/bash_completion index 114140e6..4e91a7f2 100644 --- a/bash_completion +++ b/bash_completion @@ -1607,16 +1607,16 @@ _command_offset() # find new first word position, then # rewrite COMP_LINE and adjust COMP_POINT - local word_offset=$1 - local first_word=${COMP_WORDS[$word_offset]} char_offset i - for (( i=0; i <= ${#COMP_LINE}; i++ )); do - if [[ "${COMP_LINE:$i:${#first_word}}" == "$first_word" ]]; then - char_offset=$i - break - fi + local word_offset=$1 i j + for (( i=0; i < $word_offset; i++ )); do + for (( j=0; j <= ${#COMP_LINE}; j++ )); do + [[ $COMP_LINE == ${COMP_WORDS[i]}* ]] && break + COMP_LINE=${COMP_LINE:1} + ((COMP_POINT--)) + done + COMP_LINE=${COMP_LINE#"${COMP_WORDS[i]}"} + ((COMP_POINT-=${#COMP_WORDS[i]})) done - COMP_LINE=${COMP_LINE:$char_offset} - COMP_POINT=$(( COMP_POINT - $char_offset )) # shift COMP_WORDS elements and adjust COMP_CWORD for (( i=0; i <= COMP_CWORD - $word_offset; i++ )); do |