Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: complete based on contents of another folder or folders?
- X-seq: zsh-users 16196
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: complete based on contents of another folder or folders?
- Date: Sun, 7 Aug 2011 18:40:47 +0100
- In-reply-to: <CADjGqHtmPXFbEfuw434UK=uNjGNt6KCJyPb66EukL4E2Yvf_3g@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CADjGqHtmPXFbEfuw434UK=uNjGNt6KCJyPb66EukL4E2Yvf_3g@mail.gmail.com>
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
app_path=(/Applications/*(/))
_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
found=(~/Dropbox/get_app/rcs/*(.))
found=(${found%%.*})
_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