summaryrefslogtreecommitdiff
path: root/bash_completion
diff options
context:
space:
mode:
authorFreddy Vulto <fvulto@gmail.com>2011-05-20 00:27:08 +0200
committerFreddy Vulto <fvulto@gmail.com>2011-05-20 00:27:08 +0200
commit6e7359f69c50aa57739b77a03ddff4b8c1dfef02 (patch)
treedfddec669dc770ada56e1b20d744692328629a4c /bash_completion
parent2f37a38b792aaabd8b6aff844df79a62c06eab26 (diff)
downloadbash-completion-6e7359f69c50aa57739b77a03ddff4b8c1dfef02.tar.gz
Improve _get_comp_words_by_ref()
Empty $cur with cmd = " | a " (| = cursor position) (Alioth #313102)
Diffstat (limited to 'bash_completion')
-rw-r--r--bash_completion27
1 files changed, 9 insertions, 18 deletions
diff --git a/bash_completion b/bash_completion
index caeabd36..8dd399a8 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}"
}