bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Strange compgen behaviour


From: Bernd Eggink
Subject: Re: Strange compgen behaviour
Date: Fri, 25 Sep 2009 10:04:51 +0200
User-agent: Thunderbird 2.0.0.23 (X11/20090812)

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




reply via email to

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