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

Freddy Vulto fvulto at gmail.com
Sun Sep 6 22:42:54 UTC 2009


The following commit has been merged in the master branch:
commit e663e1cbc003580debd3848769fe238ec3d631f0
Author: Freddy Vulto <fvulto at gmail.com>
Date:   Mon Sep 7 00:30:09 2009 +0200

    Reverted _get_cword
    `_get_cword' is reverted to before commit f6497298.
    This fixes unittest:
    
        "a b:c| with WORDBREAKS -= : should return b:c"
        (| = cursor position)
    
    notably by restoring passing an argument to _get_cword to omit
    characters from $COMP_WORDBREAKS.
    
    At the end of `get_cword', `echo "$cur"' has been changed to `printf
    "%s" "$cur"'.  This fixes unittest:
    
        "a -n| should return -n"
        (| = cursor position)

diff --git a/bash_completion b/bash_completion
index ff639d1..07fe78c 100644
--- a/bash_completion
+++ b/bash_completion
@@ -246,33 +246,29 @@ dequote()
 # for things like scp where we want to return host:path and not only path.
 _get_cword()
 {
-	if [[ "${#COMP_WORDS[COMP_CWORD]}" -eq 0 ]] || [[ "$COMP_POINT" == "${#COMP_LINE}" ]]; then
-		printf "%s" "${COMP_WORDS[COMP_CWORD]}"
-	else
-		local i
-		local cur="$COMP_LINE"
-		local index="$COMP_POINT"
-		for (( i = 0; i <= COMP_CWORD; ++i )); do
-			while [[ "${#cur}" -ge ${#COMP_WORDS[i]} ]] && [[ "${cur:0:${#COMP_WORDS[i]}}" != "${COMP_WORDS[i]}" ]]; do
-				cur="${cur:1}"
-				index="$(( index - 1 ))"
-			done
-			if [[ "$i" -lt "$COMP_CWORD" ]]; then
-				local old_size="${#cur}"
-				cur="${cur#${COMP_WORDS[i]}}"
-				local new_size="${#cur}"
-				index="$(( index - old_size + new_size ))"
-			fi
+	local i
+	local LC_CTYPE=C
+	local WORDBREAKS=${COMP_WORDBREAKS}
+	if [ -n $1 ]; then
+		for (( i=0; i<${#1}; ++i )); do
+			local char=${1:$i:1}
+			WORDBREAKS=${WORDBREAKS//$char/}
 		done
-
-		if [[ "${COMP_WORDS[COMP_CWORD]:0:${#cur}}" != "$cur" ]]; then
-			# We messed up! At least return the whole word so things
-			# keep working
-			printf "%s" "${COMP_WORDS[COMP_CWORD]}"
-		else
-			printf "%s" "${cur:0:$index}"
-		fi
 	fi
+	local cur=${COMP_LINE:0:$COMP_POINT}
+	local tmp="${cur}"
+	local word_start=`expr "$tmp" : '.*['"${WORDBREAKS}"']'`
+	while [ "$word_start" -ge 2 ]; do
+		local char=${cur:$(( $word_start - 2 )):1}
+		if [ "$char" != "\\" ]; then
+			break
+		fi
+		tmp=${COMP_LINE:0:$(( $word_start - 2 ))}
+		word_start=`expr "$tmp" : '.*['"${WORDBREAKS}"']'`
+	done
+
+	cur=${cur:$word_start}
+	printf "%s" "$cur"
 }
 
 # This function performs file and directory completion. It's better than

-- 
bash-completion



More information about the Bash-completion-commits mailing list