bug-bash
[Top][All Lists]
Advanced

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

Re: Strange compgen behaviour


From: Bernd Eggink
Subject: Re: Strange compgen behaviour
Date: Thu, 24 Sep 2009 10:23:04 +0200
User-agent: Thunderbird 2.0.0.23 (X11/20090812)

Mathias Dahl schrieb:
It depends heavily on how the variables IFS and zf are set. From 'man bash':

-W wordlist
    The  wordlist is split using the characters in the IFS special
    variable as delimiters, and each resultant word is expanded.
    The possible completions are the members  of  the  resultant
    list which match the word being completed.

I used a newline since the original listing comes from `find'.

You didn't say how you assigned the variable zf. If you simply did
zf=$(ls /home/mathias/Videos/movies/*), the "Brazil" line will be split
into 4 words instead of 1. However, your output suggest that you somehow
managed to combine all file names to a single word starting with
Harry.Potter.

Yes, that could be the case.

Try this: Choose a character which doesn't appear in any file name,
e.g., ':'.

     list=$(printf "%s:" /home/mathias/Videos/movies/*)
     IFS=: compgen -W "$list" -- $zc

That works, thanks! However, I also want files from sub folders to be
found, so I use `find' to list them.

Here is my latest attempt, using the idea of setting IFS to `:':

_mm2() {
    local cur files
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    files=$(find /home/mathias/Videos/movies/ -iname '*.avi' -type f -
printf "%p:")
    OLDIFS=$IFS
    IFS=:
    COMPREPLY=($(compgen -W "${files}" -- ${cur}))
    IFS=$OLDIFS
}
complete -o filenames -F _mm2 mm

Looks like it should work but it does not. Typing mm<SPC><TAB> gives
the listing and completes all the way to the path, but if I add B
again it does not match Brazil.

Hm, compgen appears to behave strange if words contain whitespace. However, you don't need it, as you build the list yourself. Try this:

 _mm2() {
     local cur files
     cur=${COMP_WORDS[COMP_CWORD]}
files=$(find /home/mathias/Videos/movies/ -iname "$cur*.avi" -type f -printf "%P\n")
     local IFS=$'\n'
     COMPREPLY=($files)
 }

Regards,
Bernd

--
Bernd Eggink
http://sudrala.de




reply via email to

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