From 3251038c9da5ba469f85870fac05ff6e3a4b7852 Mon Sep 17 00:00:00 2001 From: Freddy Vulto Date: Wed, 30 Dec 2009 09:43:16 +0100 Subject: [PATCH] Fix __reassemble_comp_words_by_ref() On bash-3, completing a b c: with COMP_WORDBREAKS -= : would result in the current word being bc: (Alioth #312190) Added unit test, run via: ./run unit/_get_cword.exp --- bash_completion | 4 ++-- test/unit/_get_cword.exp | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/bash_completion b/bash_completion index 248bd25a..7d313a66 100644 --- a/bash_completion +++ b/bash_completion @@ -228,8 +228,8 @@ __reassemble_comp_words_by_ref() { # 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 separators characters to be excluded? - while [[ $i -gt 0 && ${COMP_WORDS[$i]//[^$exclude]} ]]; do + # just word separator characters to be excluded? + while [[ $i -gt 0 && ${COMP_WORDS[$i]//[^$exclude]} == ${COMP_WORDS[$i]} ]]; do [ $j -ge 2 ] && ((j--)) # Append word separator to current word ref="$2[$j]" diff --git a/test/unit/_get_cword.exp b/test/unit/_get_cword.exp index 7e38e9ed..f71971b4 100644 --- a/test/unit/_get_cword.exp +++ b/test/unit/_get_cword.exp @@ -161,6 +161,19 @@ assert_bash_list b:c $cmd $test sync_after_int +set test {a b c:| with WORDBREAKS -= : should return c:}; # | = cursor position +if {[lindex $::BASH_VERSINFO 0] <= 3} { + set cmd {COMP_WORDS=(a b c:); COMP_CWORD=2} +} else { + set cmd {COMP_WORDS=(a b c :); COMP_CWORD=3} +}; # if +append cmd {; COMP_LINE='a b c:'; COMP_POINT=6; _get_cword :} +assert_bash_list c: $cmd $test + + +sync_after_int + + set test {a :| with WORDBREAKS -= : should return :}; # | = cursor position set cmd {COMP_WORDS=(a :); COMP_CWORD=1; COMP_LINE='a :'; COMP_POINT=3; _get_cword :} assert_bash_list : $cmd $test