[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 1.90-43-g6843989

Igor Murzov e-mail at date.by
Mon Nov 14 23:51:29 UTC 2011


The following commit has been merged in the master branch:
commit 6843989baf47e80218d89ee86b7f699c90e73be0
Author: Igor Murzov <e-mail at date.by>
Date:   Tue Nov 15 03:37:01 2011 +0300

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

diff --git a/bash_completion b/bash_completion
index 114140e..4e91a7f 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

-- 
bash-completion



More information about the Bash-completion-commits mailing list