[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 884c3f5af68e11825c7044092f7fe62975d03459

Freddy Vulto fvulto at gmail.com
Sat Oct 31 08:58:46 UTC 2009


The following commit has been merged in the master branch:
commit 884c3f5af68e11825c7044092f7fe62975d03459
Author: Freddy Vulto <fvulto at gmail.com>
Date:   Sat Oct 31 09:55:40 2009 +0100

    Fixes to _get_pword patch.
    Changed the last `echo' to a `printf' to make completing `-n' or '-e'
    come through.  Declaring a function local (break_index & word_start)
    also doesn't work on my machine: the functions become visible global.  I
    considered doing an unset -f at the end of __get_cword4, but I made them
    global (__break_index & __word_start) because they're used so often.

diff --git a/bash_completion b/bash_completion
index f648113..4878145 100644
--- a/bash_completion
+++ b/bash_completion
@@ -339,7 +339,33 @@ __get_cword3()
 # _get_cword, main routine
 # __get_cword3, bash-3 variant
 #
-[ ${BASH_VERSINFO[0]} -ge 4 ] &&
+[ ${BASH_VERSINFO[0]} -ge 4 ] && {
+# return index of first occuring break character in $1; return 0 if none
+__break_index() {
+    if [[ $1 == *[$WORDBREAKS]* ]]; then
+        local w="${1%[$WORDBREAKS]*}"
+        echo $((${#w}+1))
+    else
+        echo 0
+    fi
+} # __break_index()
+
+# return the index of the start of the last word in $@
+__word_start() {
+    local buf="$@"
+    local start="$(__break_index "$buf")"
+    while [[ $start -ge 2 ]]; do
+        # Get character before $start
+        local char="${cur:$(( start - 2 )):1}"
+        # If the WORDBREAK character isn't escaped, exit loop
+        [[ $char != \\ ]] && break
+        # The WORDBREAK character is escaped; recalculate $start
+        buf="${COMP_LINE:0:$(( start - 2 ))}"
+        start=$(__break_index "$buf")
+    done
+    echo $start
+} # __word_start()
+
 __get_cword4()
 {
     local exclude="$1" n_idx="${2:-0}"
@@ -363,41 +389,16 @@ __get_cword4()
     local cur="${COMP_LINE:0:$COMP_POINT}"
     local tmp="$cur"
 
-    local break_index word_start
-    # return index of first occuring break character in $1; return 0 if none
-    break_index() {
-        if [[ $1 == *[$WORDBREAKS]* ]]; then
-            local w="${1%[$WORDBREAKS]*}"
-            echo $((${#w}+1))
-        else
-            echo 0
-        fi
-    }
-    # return the index of the start of the last word in $@
-    word_start() {
-        local buf="$@"
-        local start="$(break_index "$buf")"
-        while [[ $start -ge 2 ]]; do
-            # Get character before $start
-            local char="${cur:$(( start - 2 )):1}"
-            # If the WORDBREAK character isn't escaped, exit loop
-            [[ $char != \\ ]] && break
-            # The WORDBREAK character is escaped; recalculate $start
-            buf="${COMP_LINE:0:$(( start - 2 ))}"
-            start=$(break_index "$buf")
-        done
-        echo $start
-    }
-
     # calculate current word, negatively offset by n_idx
-    cur="${tmp:$(word_start "$tmp")}"
+    cur="${tmp:$(__word_start "$tmp")}"
     while [[ $n_idx -gt 0 ]]; do
         local tmp="${tmp%[$WORDBREAKS]$cur}"    # truncate passed string
-        local cur="${tmp:$(word_start "$tmp")}" # then recalculate
+        local cur="${tmp:$(__word_start "$tmp")}" # then recalculate
         ((--n_idx))
     done
-    echo -n "$cur"
+    printf "%s" "$cur"
 } # __get_cword4()
+} # [ ${BASH_VERSINFO[0]} -ge 4 ]
 
 
 # This function performs file and directory completion. It's better than

-- 
bash-completion



More information about the Bash-completion-commits mailing list