bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bash-4.0 filename completion


From: Krzysiek Pawlik
Subject: Re: bash-4.0 filename completion
Date: Fri, 20 Mar 2009 20:41:15 +0000
User-agent: Thunderbird 2.0.0.21 (X11/20090319)

Chet Ramey wrote:
> I can't reproduce this.  I get a\ (escaped space), and then listing of
> possible completions with subsequent TABs.  This is the correct behavior.
> Could it have something to do with any completion functions you have
> defined?

Yes, it does. When I tested without any completion functions it works as
expected. Any tips on how to debug this issue? Setting set -x in .bashrc 
produces:

First TAB:

nelchael@nelchael ~$ cat a+ local cur opt
++ _get_cword
++ [[ 1 -eq 0 ]]
++ [[ 5 == \5 ]]
++ printf %s a
+ cur=a
+ [[ a == --*=* ]]
+ [[ a == -* ]]
+ [[ cat == rmdir ]]
+ _filedir
+ local 'IFS=
' xspec
+ _expand
+ [[ a == \~*/* ]]
+ [[ a == \~* ]]
+ toks=()
+ local toks tmp
+ toks=(${toks[@]-} $(
                compgen -d -- "$(quote_readline "$cur")" | {
                        while read -r tmp; do
                                # TODO: I've removed a "[ -n $tmp ] &&" before,
                                #       and everything works again. If this bug
                                #       suddenly appears again (i.e. "cd 
/b<TAB>"
                                #       becomes "cd /"), remember to check for
                                #       other similar conditionals (here and
                                #       _filedir_xspec()). --David
                                echo $tmp
                        done
                }
        ))
+++ quote_readline a
+++ local t=a
+++ echo ''\''a'\'''
++ compgen -d -- ''\''a'\'''
++ read -r tmp
+ [[ '' != -d ]]
+ xspec=
+ toks=(${toks[@]-} $(
                        compgen -f -X "$xspec" -- "$(quote_readline "$cur")" | {
                                while read -r tmp; do
                                        [ -n $tmp ] && echo $tmp
                                done
                        }
                ))
+++ quote_readline a
+++ local t=a
+++ echo ''\''a'\'''
++ compgen -f -X '' -- ''\''a'\'''
++ read -r tmp
++ '[' -n 'a File With spaces' ']'
++ echo 'a File With spaces'
++ read -r tmp
++ '[' -n 'a file with spaces' ']'
++ echo 'a file with spaces'
++ read -r tmp
++ '[' -n 'a File with spaces' ']'
++ echo 'a File with spaces'
++ read -r tmp
+ COMPREPLY=("${COMPREPLY[@]}" "${toks[@]}")
\

And here's output after hitting TAB again:

+ local cur opt
++ _get_cword
++ [[ 3 -eq 0 ]]
++ [[ 7 == \7 ]]
++ printf %s 'a\ '
+ cur='a\ '
+ [[ a\  == --*=* ]]
+ [[ a\  == -* ]]
+ [[ cat == rmdir ]]
+ _filedir
+ local 'IFS=
' xspec
+ _expand
+ [[ a\  == \~*/* ]]
+ [[ a\  == \~* ]]
+ toks=()
+ local toks tmp
+ toks=(${toks[@]-} $(
                compgen -d -- "$(quote_readline "$cur")" | {
                        while read -r tmp; do
                                # TODO: I've removed a "[ -n $tmp ] &&" before,
                                #       and everything works again. If this bug
                                #       suddenly appears again (i.e. "cd 
/b<TAB>"
                                #       becomes "cd /"), remember to check for
                                #       other similar conditionals (here and
                                #       _filedir_xspec()). --David
                                echo $tmp
                        done
                }
        ))
+++ quote_readline 'a\ '
+++ local 't=a\\ '
+++ echo ''\''a\\ '\'''
++ compgen -d -- ''\''a\\ '\'''
++ read -r tmp
+ [[ '' != -d ]]
+ xspec=
+ toks=(${toks[@]-} $(
                        compgen -f -X "$xspec" -- "$(quote_readline "$cur")" | {
                                while read -r tmp; do
                                        [ -n $tmp ] && echo $tmp
                                done
                        }
                ))
++ read -r tmp
+++ quote_readline 'a\ '
+++ local 't=a\\ '
+++ echo ''\''a\\ '\'''
++ compgen -f -X '' -- ''\''a\\ '\'''
+ COMPREPLY=("${COMPREPLY[@]}" "${toks[@]}")

The same function works in 3.2 ok, below is _filedir():

_filedir()
{
        local IFS=$'\t\n' xspec

        _expand || return 0

        local toks=( ) tmp

        toks=( ${toks[@]-} $(
                compgen -d -- "$(quote_readline "$cur")" | {
                        while read -r tmp; do
                                # TODO: I've removed a "[ -n $tmp ] &&" before,
                                #       and everything works again. If this bug
                                #       suddenly appears again (i.e. "cd 
/b<TAB>"
                                #       becomes "cd /"), remember to check for
                                #       other similar conditionals (here and
                                #       _filedir_xspec()). --David
                                echo $tmp
                        done
                }
        ))

        if [[ "$1" != -d ]]; then
                xspec=${1:+"!*.$1"}
                toks=( ${toks[@]-} $(
                        compgen -f -X "$xspec" -- "$(quote_readline "$cur")" | {
                                while read -r tmp; do
                                        [ -n $tmp ] && echo $tmp
                                done
                        }
                ))
        fi

        COMPREPLY=( "${COMPREPLY[@]}" "${toks[@]}" )
}

-- 
Krzysiek Pawlik   <nelchael at gentoo.org>   key id: 0xBC555551
desktop-misc, java, apache, ppc, vim, kernel, python...

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]