zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-users@sunsite.dk
Subject: Re: completion argument-n enabling
Date: Thu, 02 Mar 2006 16:05:44 +0000	[thread overview]
Message-ID: <EXCHANGE03smriiEIJM000126e3@exchange03.csr.com> (raw)
In-Reply-To: <20060302123735.GA16201@parhelion.globnix.org>

Phil Pennock wrote:
> Given:
>  function cyrus { sudo -H -u cyrus "/usr/lib/cyrus/$1" "${argv[2,-1]}" }
> I've managed to produce a mostly-working set-up:
>  zstyle ':completion:*:*:cyrus:*' file-patterns '/usr/lib/cyrus/*(*\:t)'
> 
> However, I only want that completion to occur for the first parameter;
> but argument-n context needs to be enabled and I can't figure out how to
> do that.  To make:
>  zstyle ':completion:*:*:cyrus:argument-1:*' file-patterns \
> 						 '/usr/lib/cyrus/*(*\:t)'
> work, what do I actually need to do please?  The nearest that I could
> figure out was: zstyle ':completion:*:*:cyrus:*:arguments' _normal
> but that doesn't work.

As far as I know, only the _arguments completer has that capability,
so you need

_cyrus() {
    _arguments \
      ':cyrus file:_path_files -g "/usr/lib/cyrus/*(*\:t)"'
}

Note that you'll also get directories in /usr/lib/cyrus, although
I suppose there aren't any.  Stick a "." after the "(" to fix that.

> Also, if I instead use:
>  compdef '_files -g "/usr/lib/cyrus/*(*:t)"' -P '' cyrus
> (I know, it deals with all parameters, not just the first) why am I
> prompted with two sets of results, the correct filenames and then the
> sub-directories of the cwd?

_files tries to be smart about paths, but if you're trying to specify an
explicit path you don't want it to be.  Use the underlying function
_path_files, as I did above.

> Are there any simple examples which I should be looking for, covering
> this sort of thing?  The stuff I can find all uses custom _cmdname
> widgets and I couldn't find anything just offering plain "how to do X"
> for the sort of thing I'm attempting.  The nearest seems to be
> StartupFiles/zshrc which falls just shy of providing an example of
> per-command completion.

There are lots of examples of using _arguments in all sorts of different
ways.

Of course, if you really want a good explanation you need to buy From
Bash to Z Shell:  Conquering the Command Line (Apress).

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php


      reply	other threads:[~2006-03-02 16:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-02 12:37 Phil Pennock
2006-03-02 16:05 ` Peter Stephenson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=EXCHANGE03smriiEIJM000126e3@exchange03.csr.com \
    --to=pws@csr.com \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).