Package: bash-completion Version: 20060301-4 Followup-For: Bug #474094 Hi,
Today I installed bash-completion and I got same bug. This bug also affects to file name as well as directory name. $ touch "foo bar.zip" $ ls foo bar.zip $ unzip "foo b[TAB] -> does not work In addition to spaces, it is caused by other characters specified in $COMP_WORDBREAKS variable. $ echo -n "$COMP_WORDBREAKS" | hexdump -C 00000000 20 09 0a 22 27 3e 3c 3d 3b 7c 26 28 3a | .."'><=;|&(:| 0000000d $ touch "foo(barbarbar).avi" "123=456.avi" "abc&def.avi" $ ls 123=456.avi abc&def.avi foo(barbarbar).avi $ mplayer "123=4[TAB] -> does not work $ mplayer "abc&d[TAB] -> does not work $ mplayer "foo(bar[TAB] -> does not work Although quoted by " or ' does not work, quoted by \ works correctly. $ unzip foo\ b[TAB] -> foo\ bar.zip It seems that the condition to produce this bug is as follow: * the name contains one of $COMP_WORDBREAKS characters, * and is quoted by " or ' * and press TAB after $COMP_WORDBREAKS character. After some investigation for /etc/bash_completion, I found the function _get_cword() has a problem. The function _get_cword() was originally introduced to fix following bug in ubuntu: Bug #139666 in bash-completion (Ubuntu): “bash completion doesn't work in the middle of a word” https://bugs.launchpad.net/ubuntu/+source/bash-completion/+bug/139666 The function _get_cword() returns the current word that cursor is pointed. The problem is, _get_cword considers only \ quoting, not considers " or ' quoting. So that, _get_cword thinks the word "foo b is 2 words, '"foo' and 'b'. That is a reason why " or ' quoting not work although \ quoting works. I have 2 ideas to fix the problem. 1) revert to old (before #139666) behaviour. _get_cword() { printf "%s" "${COMP_WORDS[$COMP_CWORD]}"; } 2) improve current behaviour to handle " and ' quoting correctly. # Quote regular expression meta characters _quotemeta() { printf "%s" "$( printf "%s" "$1" | sed 's/\\/\\\\/g; s/[.*[$^]/\\&/g; s/[?+{()|]/[&]/g' )" } # Get the word to complete # This is nicer than ${COMP_WORDS[$COMP_CWORD]}, since it handles cases # where the user is completing in the middle of a word. # (For example, if the line is "ls foobar", # and the cursor is here --------> ^ # it will complete just "foo", not "foobar", which is what the user wants.) _get_cword() { local pattern local i pattern=$'[ \t\n]*' for (( i=0; i < $COMP_CWORD; i++ )); do pattern="${pattern}$( _quotemeta "${COMP_WORDS[$i]}" )"$'[ \t\n]\+' done local offset_for_cword="$( expr "$COMP_LINE" : "$pattern" )" local point_on_cword=$(( $COMP_POINT - $offset_for_cword )); local LC_CTYPE=C printf "%s" "${COMP_LINE:$offset_for_cword:$point_on_cword}" } Note: I think it is better to use printf instead of echo. echo prints empty string in case of echo "$str" and $str is "-e" or "-n" (a string that is option for echo.) So if we use echo, completion for a string that start with "-e" or "-n" works incorrectly. Regards, -- System Information: Debian Release: lenny/sid APT prefers unstable APT policy: (500, 'unstable') Architecture: i386 (i686) Kernel: Linux 2.6.25-1-686 (SMP w/1 CPU core) Locale: LANG=ja_JP.UTF-8, LC_CTYPE=ja_JP.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/bash Versions of packages bash-completion depends on: ii bash 3.2-2 The GNU Bourne Again SHell ii ucf 3.006 Update Configuration File: preserv bash-completion recommends no packages. -- no debconf information -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]