[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 1.3-309-g6e7359f
Freddy Vulto
fvulto at gmail.com
Thu May 19 22:27:41 UTC 2011
The following commit has been merged in the master branch:
commit 6e7359f69c50aa57739b77a03ddff4b8c1dfef02
Author: Freddy Vulto <fvulto at gmail.com>
Date: Fri May 20 00:27:08 2011 +0200
Improve _get_comp_words_by_ref()
Empty $cur with cmd = " | a " (| = cursor position)
(Alioth #313102)
diff --git a/CHANGES b/CHANGES
index 0ca0edc..40a869f 100644
--- a/CHANGES
+++ b/CHANGES
@@ -40,8 +40,9 @@ bash-completion (2.x)
[ Freddy Vulto ]
* Improve __reassemble_comp_words_by_ref() to not create words of
characters-to-exclude (Alioth: #313057)
- * Improve _get_comp_words_by_ref() with cursor at position 0. Patch by
- Igor Murzov (Debian: #559953)
+ * Fix _get_comp_words_by_ref() with cursor at position 0. Patch by Igor
+ Murzov (Debian: #559953).
+ * Fix _get_comp_words_by_ref() with spaces before cursor (Alioth #313102).
[ Mattias Ulbrich ]
* Make java class completion suggest packages.
diff --git a/bash_completion b/bash_completion
index caeabd3..8dd399a 100644
--- a/bash_completion
+++ b/bash_completion
@@ -348,9 +348,9 @@ __get_cword_at_cursor_by_ref()
local cword words=()
__reassemble_comp_words_by_ref "$1" words cword
- local i cur cur2
- local index=$COMP_POINT
- if (( index )); then
+ local i cur cur2 index=$COMP_POINT lead=${COMP_LINE:0:$COMP_POINT}
+ # Cursor not at position 0 and not leaded by just space(s)?
+ if [[ $index -gt 0 && ( $lead && ${lead//[[:space:]]} ) ]]; then
cur=$COMP_LINE
for (( i = 0; i <= cword; ++i )); do
while [[
@@ -374,23 +374,14 @@ __get_cword_at_cursor_by_ref()
index=$(( index - old_size + new_size ))
fi
done
+ # Clear $cur if just space(s)
+ [[ $cur && ! ${cur//[[:space:]]} ]] && cur=
+ # Zero $index if negative
+ [[ $index -lt 0 ]] && index=0
fi
- if [[ $index -lt 0 ]]; then
- # This happens when completing: "command | arg" (| is where
- # TAB is hit)
- index=0
- fi
-
- if [[ "${words[cword]:0:${#cur}}" != "$cur" ]]; then
- # We messed up. At least return the whole word so things keep working
- cur2=${words[cword]}
- else
- cur2=${cur:0:$index}
- fi
-
- local "$2" "$3" "$4" &&
- _upvars -a${#words[@]} $2 "${words[@]}" -v $3 "$cword" -v $4 "$cur2"
+ local "$2" "$3" "$4" && _upvars -a${#words[@]} $2 "${words[@]}" \
+ -v $3 "$cword" -v $4 "${cur:0:$index}"
}
--
bash-completion
More information about the Bash-completion-commits
mailing list