bug-bash
[Top][All Lists]
Advanced

[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!


reply via email to

[Prev in Thread] Current Thread [Next in Thread]