Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: complete based on contents of another folder or folders?

On Sun, 7 Aug 2011 06:21:49 -0400
TJ Luoma <luomat@xxxxxxxxx> wrote:
> I know almost nothing about Zsh's completion feature, other than it's
> cool and I wish I took better advantage of it.
> Here's are some of first things I'd like to do. I'm hoping that
> someone might be able to explain this in a way that will allow me to
> replicate this in other scenarios.
> 1)
> "open -a [tab]" should offer "any file found in
> /Applications/
> /Applications/Microsoft Office 2011/
> /Applications/Utilities/
> /Applications/iWork '09/
> which ends with '.app' and should not show the dirname (and doesn't
> need to show the '.app' suffix, but that's not crucial).

You want something like

_open() {          
  local -a app_path
  _path_files -W app_path -g '*.app'
compdef _open open
> 2) Similarly
>         get_app [tab]
> should offer completions based on files found in
> ~/Dropbox/get_app/rcs/ with the following stipulations:
> - I only want the part of the filename up until the first literal "."
> (and each file has at least one ".")
> - no filenames do NOT have spaces in them
> - subfolders may exist, but should be ignored (same is true for files
> which begin with '.')

Probably easiest to use globbing in the completion function rather than
file completion.

_get_app() {
   local -a found
   local expl

   _wanted apps expl 'app' compadd -a found

Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/

Messages sorted by: Reverse Date, Date, Thread, Author