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

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
    files=$(find /home/mathias/Videos/movies/ -iname '*.avi' -type f -
printf "%p:")
    COMPREPLY=($(compgen -W "${files}" -- ${cur}))
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
files=$(find /home/mathias/Videos/movies/ -iname "$cur*.avi" -type f -printf "%P\n")
     local IFS=$'\n'


Bernd Eggink

Reply via email to