[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 3f0bfbc5aea5efb1d9b20384e8291d9785bf3ae0

Freddy Vulto fvulto at gmail.com
Thu Dec 31 10:13:27 UTC 2009


The following commit has been merged in the master branch:
commit 3f0bfbc5aea5efb1d9b20384e8291d9785bf3ae0
Author: Freddy Vulto <fvulto at gmail.com>
Date:   Thu Dec 31 11:12:15 2009 +0100

    Fix __reassemble_comp_words_by_ref()
    Completing "a b " returned cur=b instead of cur=nothing if a wordbreak
    character was specified.

diff --git a/bash_completion b/bash_completion
index 7d313a6..0747fd6 100644
--- a/bash_completion
+++ b/bash_completion
@@ -222,14 +222,19 @@ __reassemble_comp_words_by_ref() {
         exclude="${1//[^$COMP_WORDBREAKS]}"
     fi
         
+    # Default to cword unchanged
+    eval $3=$COMP_CWORD
     # Are characters excluded which were former included?
     if [[ $exclude ]]; then
         # Yes, list of word completion separators has shrunk;
         # Re-assemble words to complete
         for (( i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
-            # Is current word not word 0 (the command itself) and is word made up of
-            # just word separator characters to be excluded?
-            while [[ $i -gt 0 && ${COMP_WORDS[$i]//[^$exclude]} == ${COMP_WORDS[$i]} ]]; do
+            # Is current word not word 0 (the command itself) and is word not
+            # empty and is word made up of just word separator characters to be
+            # excluded?
+            while [[ $i -gt 0 && ${COMP_WORDS[$i]} && 
+                ${COMP_WORDS[$i]//[^$exclude]} == ${COMP_WORDS[$i]} 
+            ]]; do
                 [ $j -ge 2 ] && ((j--))
                 # Append word separator to current word
                 ref="$2[$j]"
@@ -243,12 +248,11 @@ __reassemble_comp_words_by_ref() {
             ref="$2[$j]"
             eval $2[$j]=\${!ref}\${COMP_WORDS[i]}
             # Indicate new cword
-            [ $i = $COMP_CWORD ] && eval $3=$j
+            [ $i = $COMP_CWORD ] && [[ ${COMP_WORDS[i]} ]] && eval $3=$j
         done
     else
         # No, list of word completions separators hasn't changed;
         eval $2=\( \"\${COMP_WORDS[@]}\" \)
-        eval $3=$COMP_CWORD
     fi
 } # __reassemble_comp_words_by_ref()
 
diff --git a/test/unit/_get_cword.exp b/test/unit/_get_cword.exp
index f71971b..25e0e8d 100644
--- a/test/unit/_get_cword.exp
+++ b/test/unit/_get_cword.exp
@@ -45,6 +45,24 @@ expect -ex "$cmd\r\n/@" {pass "$test"}
 sync_after_int
 
 
+set test "a b | should return nothing";  # | = cursor position
+set cmd {COMP_WORDS=(a b ''); COMP_CWORD=2; COMP_LINE='a b '; COMP_POINT=4; _get_cword}
+send "$cmd\r"
+expect -ex "$cmd\r\n/@" {pass "$test"}
+
+
+sync_after_int
+
+
+set test "a b | with WORDBREAKS -= : should return nothing";  # | = cursor position
+set cmd {COMP_WORDS=(a b ''); COMP_CWORD=2; COMP_LINE='a b '; COMP_POINT=4; _get_cword :}
+send "$cmd\r"
+expect -ex "$cmd\r\n/@" {pass "$test"}
+
+
+sync_after_int
+
+
 set test "a b|c should return b";  # | = cursor position
 set cmd {COMP_WORDS=(a bc); COMP_CWORD=1; COMP_LINE='a bc'; COMP_POINT=3; _get_cword}
 assert_bash_list b $cmd $test

-- 
bash-completion



More information about the Bash-completion-commits mailing list