Fix __reassemble_comp_words_by_ref()

Completing "a b " returned cur=b instead of cur=nothing if a wordbreak
character was specified.
master
Freddy Vulto 2009-12-31 11:12:15 +01:00
parent 07db41e38f
commit 3f0bfbc5ae
2 changed files with 27 additions and 5 deletions

View File

@ -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()

View File

@ -45,6 +45,24 @@ expect -ex "$cmd\r\n/@" {pass "$test"}
sync_after_int
set test "a b | should return nothing"; # | = cursor position
set cmd {COMP_WORDS=(a b ''); COMP_CWORD=2; COMP_LINE='a b '; COMP_POINT=4; _get_cword}
send "$cmd\r"
expect -ex "$cmd\r\n/@" {pass "$test"}
sync_after_int
set test "a b | with WORDBREAKS -= : should return nothing"; # | = cursor position
set cmd {COMP_WORDS=(a b ''); COMP_CWORD=2; COMP_LINE='a b '; COMP_POINT=4; _get_cword :}
send "$cmd\r"
expect -ex "$cmd\r\n/@" {pass "$test"}
sync_after_int
set test "a b|c should return b"; # | = cursor position
set cmd {COMP_WORDS=(a bc); COMP_CWORD=1; COMP_LINE='a bc'; COMP_POINT=3; _get_cword}
assert_bash_list b $cmd $test