Fix __reassemble_comp_words_by_ref()

If a word is made up of multiple word separator characters:

   $ a b::<TAB>  # CWORDS are: a, b, and :: (correct)

__reassemble_comp_words_by_ref() couldn't handle this.  It assumed CWORDS were:

   $ a b::<TAB>  # CWORDS: a, b, : and : (but they're not)

Added test case for this.  To run the automated tests:

   ./runUnit _get_cword.exp
This commit is contained in:
Freddy Vulto 2009-12-10 21:28:24 +01:00
parent 0f25d9c66f
commit b1e58b1a0e
2 changed files with 16 additions and 3 deletions

View File

@ -234,9 +234,9 @@ __reassemble_comp_words_by_ref() {
# 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 of
# length 1 and is word newly excluded from being word separator?
while [[ $i -gt 0 && ${#COMP_WORDS[$i]} == 1 && ${COMP_WORDS[$i]//[^$exclude]} ]]; do
# Is current word not word 0 (the command itself) and is word made up of
# just word separators characters to be excluded?
while [[ $i -gt 0 && ${COMP_WORDS[$i]//[^$exclude]} ]]; do
[ $j -ge 2 ] && ((j--))
# Append word separator to current word
ref="$2[$j]"

View File

@ -171,6 +171,19 @@ assert_bash_list : $cmd $test
sync_after_int
set test {a b::| with WORDBREAKS -= : should return b::}; # | = cursor position
if {[lindex $::BASH_VERSINFO 0] <= 3} {
set cmd {COMP_WORDS=(a "b::"); COMP_CWORD=1}
} else {
set cmd {COMP_WORDS=(a b ::); COMP_CWORD=2}
}; # if
append cmd {; COMP_LINE='a b::'; COMP_POINT=5; _get_cword :}
assert_bash_list b:: $cmd $test
sync_after_int
# This test makes sure `_get_cword' doesn't use `echo' to return it's value,
# because -n might be interpreted by `echo' and thus will not be returned.
set test "a -n| should return -n"; # | = cursor position