summaryrefslogtreecommitdiff
path: root/bash_completion
diff options
context:
space:
mode:
authorFreddy Vulto <fvulto@gmail.com>2009-12-31 11:12:15 +0100
committerFreddy Vulto <fvulto@gmail.com>2009-12-31 11:12:15 +0100
commit3f0bfbc5aea5efb1d9b20384e8291d9785bf3ae0 (patch)
treedcd7be842ab52c86a24df526a49777780eafbee1 /bash_completion
parent07db41e38f5d4da5499cc3eec6dfe01fb738c415 (diff)
downloadbash-completion-3f0bfbc5aea5efb1d9b20384e8291d9785bf3ae0.tar.gz
Fix __reassemble_comp_words_by_ref()
Completing "a b " returned cur=b instead of cur=nothing if a wordbreak character was specified.
Diffstat (limited to 'bash_completion')
-rw-r--r--bash_completion14
1 files changed, 9 insertions, 5 deletions
diff --git a/bash_completion b/bash_completion
index 7d313a66..0747fd66 100644
--- a/bash_completion
+++ b/bash_completion
@@ -222,14 +222,19 @@ __reassemble_comp_words_by_ref() {
exclude="${1//[^$COMP_WORDBREAKS]}"
fi
+ # Default to cword unchanged
+ eval $3=$COMP_CWORD
# Are characters excluded which were former included?
if [[ $exclude ]]; then
# Yes, list of word completion separators has shrunk;
# Re-assemble words to complete
for (( i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
- # Is current word not word 0 (the command itself) and is word made up of
- # just word separator characters to be excluded?
- while [[ $i -gt 0 && ${COMP_WORDS[$i]//[^$exclude]} == ${COMP_WORDS[$i]} ]]; do
+ # Is current word not word 0 (the command itself) and is word not
+ # empty and is word made up of just word separator characters to be
+ # excluded?
+ while [[ $i -gt 0 && ${COMP_WORDS[$i]} &&
+ ${COMP_WORDS[$i]//[^$exclude]} == ${COMP_WORDS[$i]}
+ ]]; do
[ $j -ge 2 ] && ((j--))
# Append word separator to current word
ref="$2[$j]"
@@ -243,12 +248,11 @@ __reassemble_comp_words_by_ref() {
ref="$2[$j]"
eval $2[$j]=\${!ref}\${COMP_WORDS[i]}
# Indicate new cword
- [ $i = $COMP_CWORD ] && eval $3=$j
+ [ $i = $COMP_CWORD ] && [[ ${COMP_WORDS[i]} ]] && eval $3=$j
done
else
# No, list of word completions separators hasn't changed;
eval $2=\( \"\${COMP_WORDS[@]}\" \)
- eval $3=$COMP_CWORD
fi
} # __reassemble_comp_words_by_ref()