From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21857 invoked from network); 2 Mar 2006 16:09:10 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.0 (2005-09-13) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00, FORGED_RCVD_HELO autolearn=ham version=3.1.0 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 2 Mar 2006 16:09:10 -0000 Received: (qmail 83942 invoked from network); 2 Mar 2006 16:09:04 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 2 Mar 2006 16:09:04 -0000 Received: (qmail 5906 invoked by alias); 2 Mar 2006 16:08:55 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 9977 Received: (qmail 5897 invoked from network); 2 Mar 2006 16:08:55 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 2 Mar 2006 16:08:54 -0000 Received: (qmail 82718 invoked from network); 2 Mar 2006 16:08:54 -0000 Received: from cluster-d.mailcontrol.com (217.69.20.190) by a.mx.sunsite.dk with SMTP; 2 Mar 2006 16:08:53 -0000 Received: from exchange03.csr.com (uuk202166.uk.customer.alter.net [62.189.241.194] (may be forged)) by rly34d.srv.mailcontrol.com (MailControl) with ESMTP id k22G3F1l007772 for ; Thu, 2 Mar 2006 16:08:48 GMT Received: from csr.com ([10.103.143.38]) by exchange03.csr.com with Microsoft SMTPSVC(5.0.2195.6713); Thu, 2 Mar 2006 16:05:59 +0000 To: zsh-users@sunsite.dk Subject: Re: completion argument-n enabling In-reply-to: <20060302123735.GA16201@parhelion.globnix.org> References: <20060302123735.GA16201@parhelion.globnix.org> Date: Thu, 02 Mar 2006 16:05:44 +0000 From: Peter Stephenson Message-ID: X-OriginalArrivalTime: 02 Mar 2006 16:05:59.0115 (UTC) FILETIME=[320559B0:01C63E13] Content-Type: text/plain MIME-Version: 1.0 X-Scanned-By: MailControl A-06-00-05 (www.mailcontrol.com) on 10.68.0.144 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 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