Re: Strange compgen behaviour

2009-10-01 Thread Mathias Dahl
I decided to make this into a blog post to in some way contribute back to the community for all the help I got. http://muublog.blogspot.com/2009/10/bash-completion-for-playing-movies.html Enjoy! /Mathias

Re: Strange compgen behaviour

2009-09-25 Thread Bernd.Eggink
Chet Ramey schrieb: Bernd Eggink wrote: Chet Ramey schrieb: Hm, compgen appears to behave strange if words contain whitespace. Well, it splits the argument to -W on $IFS as documented. What other strange behavior do you see? For example, this: function _aha { local list="a

Re: Strange compgen behaviour

2009-09-25 Thread Mathias Dahl
> printf "%q\n" works fine here. It does here too :), I misunderstood the syntax. > Also, grep "${cur}" could probably be replaced by -path "*/${cur}*". Indeed it can. Smaller = better, thanks! /Mathias

Re: Strange compgen behaviour

2009-09-25 Thread Chet Ramey
Bernd Eggink wrote: > Chet Ramey schrieb: >>> Hm, compgen appears to behave strange if words contain whitespace. >> >> Well, it splits the argument to -W on $IFS as documented. What other >> strange behavior do you see? > > For example, this: > > function _aha > { > local list=

Re: Strange compgen behaviour

2009-09-25 Thread Andreas Schwab
Mathias Dahl writes: > Got this to work: > > files=$(find /home/mathias/Videos/movies/ -iname "*.avi" -type f - > printf "%P\n" | grep "${cur}" | while read file; do > printf %q "$file" > echo > done) > > With the %q option to printf it no longer accepts a \n so I nee

Re: Strange compgen behaviour

2009-09-25 Thread Mathias Dahl
> Interesting! Can I make it part of my pipe (in place of `sed') or need > I change it to a for or while loop? This is what I have now: > > files=$(find /home/mathias/Videos/movies/ -iname "*.avi" -type f - > printf "%P\n" | grep "${cur}" | sed "s/\\([][\\(\\) ,\']\\)/\\1/ > g") Got this to wo

Re: Strange compgen behaviour

2009-09-25 Thread Mathias Dahl
> printf %q "$filename" > > will either insert backslashes in front of all the shell metacharacters, > or $'...' quote the whole thing, or take some other action which renders > a string "safe".  It's basically the opposite of eval. Interesting! Can I make it part of my pipe (in place of `sed') o

Re: Strange compgen behaviour

2009-09-25 Thread Mathias Dahl
> This has been an interesting topic! I thought I should share the final version as well: _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}" | sed "s/\\([][\\(\\) ,\'

Re: Strange compgen behaviour

2009-09-25 Thread Greg Wooledge
On Thu, Sep 24, 2009 at 03:05:07PM -0700, Mathias Dahl wrote: > I did not find any generic way to quote/escape file names so I > hardcoded some chars I know exist in my file names and used sed: printf %q "$filename" will either insert backslashes in front of all the shell metacharacters, or $'...

Re: Strange compgen behaviour

2009-09-25 Thread Mathias Dahl
> 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" (

Re: Strange compgen behaviour

2009-09-25 Thread Bernd Eggink
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" -

Re: Strange compgen behaviour

2009-09-24 Thread Mathias Dahl
> ...but then I have to shell quote the file name myself to handle > spaces, brackets of various sorts, comma characters etc. Will hunt for > such a function and see. There are all sorts of crazy helper functions > in /etc/bash_completion, of which I barely understand anything. I did not find any

Re: Strange compgen behaviour

2009-09-24 Thread Mathias Dahl
> 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 -p

Re: Strange compgen behaviour

2009-09-24 Thread Chris F.A. Johnson
On Thu, 24 Sep 2009, Bernd Eggink wrote: > Chet Ramey schrieb: > > > Hm, compgen appears to behave strange if words contain whitespace. > > > > Well, it splits the argument to -W on $IFS as documented. What other > > strange behavior do you see? > > For example, this: > > function _aha >

Re: Strange compgen behaviour

2009-09-24 Thread Chet Ramey
Bernd Eggink wrote: > Chet Ramey schrieb: >>> Hm, compgen appears to behave strange if words contain whitespace. >> >> Well, it splits the argument to -W on $IFS as documented. What other >> strange behavior do you see? > > For example, this: > > function _aha > { > local list=

Re: Strange compgen behaviour

2009-09-24 Thread Bernd Eggink
Chet Ramey schrieb: Hm, compgen appears to behave strange if words contain whitespace. Well, it splits the argument to -W on $IFS as documented. What other strange behavior do you see? For example, this: function _aha { local list="a b:c d:e f" COMPREPLY=($(IFS=: co

Re: Strange compgen behaviour

2009-09-24 Thread Chet Ramey
> Hm, compgen appears to behave strange if words contain whitespace. Well, it splits the argument to -W on $IFS as documented. What other strange behavior do you see? Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates

Re: Strange compgen behaviour

2009-09-24 Thread Bernd Eggink
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

Re: Strange compgen behaviour

2009-09-23 Thread Mathias Dahl
> 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 >

Re: Strange compgen behaviour

2009-09-23 Thread Bernd Eggink
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 a