[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 1.3-308-g2f37a38
Freddy Vulto
fvulto at gmail.com
Thu May 19 20:48:32 UTC 2011
The following commit has been merged in the master branch:
commit 2f37a38b792aaabd8b6aff844df79a62c06eab26
Author: Freddy Vulto <fvulto at gmail.com>
Date: Thu May 19 22:47:00 2011 +0200
Improve _get_comp_words_by_ref()
Empty $cur when cmd = "|a " (| = cursor position)
diff --git a/bash_completion b/bash_completion
index d3507fb..caeabd3 100644
--- a/bash_completion
+++ b/bash_completion
@@ -348,31 +348,33 @@ __get_cword_at_cursor_by_ref()
local cword words=()
__reassemble_comp_words_by_ref "$1" words cword
- local i cur2
- local cur="$COMP_LINE"
- local index="$COMP_POINT"
- for (( i = 0; i <= cword; ++i )); do
- while [[
- # Current word fits in $cur?
- "${#cur}" -ge ${#words[i]} &&
- # $cur doesn't match cword?
- "${cur:0:${#words[i]}}" != "${words[i]}"
- ]]; do
- # Strip first character
- cur="${cur:1}"
- # Decrease cursor position
- ((index--))
- done
+ local i cur cur2
+ local index=$COMP_POINT
+ if (( index )); then
+ cur=$COMP_LINE
+ for (( i = 0; i <= cword; ++i )); do
+ while [[
+ # Current word fits in $cur?
+ "${#cur}" -ge ${#words[i]} &&
+ # $cur doesn't match cword?
+ "${cur:0:${#words[i]}}" != "${words[i]}"
+ ]]; do
+ # Strip first character
+ cur="${cur:1}"
+ # Decrease cursor position
+ ((index--))
+ done
- # Does found word match cword?
- if [[ "$i" -lt "$cword" ]]; then
- # No, cword lies further;
- local old_size="${#cur}"
- cur="${cur#${words[i]}}"
- local new_size="${#cur}"
- index=$(( index - old_size + new_size ))
- fi
- done
+ # Does found word match cword?
+ if [[ "$i" -lt "$cword" ]]; then
+ # No, cword lies further;
+ local old_size="${#cur}"
+ cur="${cur#${words[i]}}"
+ local new_size="${#cur}"
+ index=$(( index - old_size + new_size ))
+ fi
+ done
+ fi
if [[ $index -lt 0 ]]; then
# This happens when completing: "command | arg" (| is where
--
bash-completion
More information about the Bash-completion-commits
mailing list