Mathias Dahl schrieb:
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) }Ah, you're right of course, I can do the matching myself. I have yet another version working now (had to change your latest suggestion and use grep for matching because -name does not like full paths which becomes the case here): _mm() { local cur files COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" files=$(find /home/mathias/Videos/movies/ -iname "*.avi" -type f - printf "%p\n" | grep "${cur}") local IFS=$'\n' COMPREPLY=(${files}) } complete -o filenames -F _mm mm Now, this works almost. The remaining problem is that because `find' finds file in subdirs (which I want, otherwise I could add the - maxdepth option) as well, the `-o filenames' argument to `complete' does not play well with it. I see the names of files in subdirs listed when I type TAB (without path) but can never pick them without knowing the name of the folder they are in.
Hm, I can't see any problem here. My version lets you pick any file in any subdir by simply typing the name (or part of it) without the directory part. After all, 'find -name' matches names, not paths (if you want to match full paths, use 'find -path'). I'd also rather use printf "%P\n" (capital P) instead of %p, the results look nicer (IMHO).
Regards, Bernd -- Bernd Eggink http://sudrala.de
