Mathias Dahl schrieb:
Hi fellow bashers!

I am trying to add some completion to a command. The completion should
list all movies I have in a certain folder, regardless if I am in that
folder or not. I have kind of got it to work in several variants but
all have some issue. The current problem I am looking at is very
strange. I have isolated it down to a strange behaviour with compgen.
Let's see if I can describe it clearly enough:

zf contains the list of movie file names
zc is the current input, in my case "/home/mathias/Videos/movies/H"

$ compgen -W "${zf}" -- ${zc}

Here is the output:

/home/mathias/Videos/movies/Brazil (Terry Gilliam, 1985).avi

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.

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.

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


Bernd Eggink

Reply via email to