[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Strange compgen behaviour
From: |
Mathias Dahl |
Subject: |
Re: Strange compgen behaviour |
Date: |
Thu, 24 Sep 2009 14:04:59 -0700 (PDT) |
User-agent: |
G2/1.0 |
> 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. So I have to get rid of that
option, 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.
Thanks!
- Strange compgen behaviour, Mathias Dahl, 2009/09/23
- Re: Strange compgen behaviour, Bernd Eggink, 2009/09/23
- Message not available
- Re: Strange compgen behaviour, Mathias Dahl, 2009/09/23
- Re: Strange compgen behaviour, Bernd Eggink, 2009/09/24
- Re: Strange compgen behaviour, Chet Ramey, 2009/09/24
- Re: Strange compgen behaviour, Bernd Eggink, 2009/09/24
- Re: Strange compgen behaviour, Chet Ramey, 2009/09/24
- Re: Strange compgen behaviour, Chris F.A. Johnson, 2009/09/24
- Re: Strange compgen behaviour, Chet Ramey, 2009/09/25
- Re: Strange compgen behaviour, Bernd.Eggink, 2009/09/25
- Message not available
- Re: Strange compgen behaviour,
Mathias Dahl <=
- Re: Strange compgen behaviour, Mathias Dahl, 2009/09/24
- Re: Strange compgen behaviour, Greg Wooledge, 2009/09/25
- Message not available
- Re: Strange compgen behaviour, Mathias Dahl, 2009/09/25
- Re: Strange compgen behaviour, Mathias Dahl, 2009/09/25
- Re: Strange compgen behaviour, Andreas Schwab, 2009/09/25
- Message not available
- Re: Strange compgen behaviour, Mathias Dahl, 2009/09/25
- Re: Strange compgen behaviour, Bernd Eggink, 2009/09/25
- Message not available
- Re: Strange compgen behaviour, Mathias Dahl, 2009/09/25
- Re: Strange compgen behaviour, Mathias Dahl, 2009/09/25