From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29544 invoked from network); 22 Nov 2006 21:31:46 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.7 (2006-10-05) 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.7 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 22 Nov 2006 21:31:46 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 66406 invoked from network); 22 Nov 2006 21:31:40 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 22 Nov 2006 21:31:40 -0000 Received: (qmail 12938 invoked by alias); 22 Nov 2006 21:31:31 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 11017 Received: (qmail 12927 invoked from network); 22 Nov 2006 21:31:30 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 22 Nov 2006 21:31:30 -0000 Received: (qmail 65247 invoked from network); 22 Nov 2006 21:31:30 -0000 Received: from wx-out-0506.google.com (66.249.82.230) by a.mx.sunsite.dk with SMTP; 22 Nov 2006 21:31:27 -0000 Received: by wx-out-0506.google.com with SMTP id i31so332289wxd for ; Wed, 22 Nov 2006 13:31:25 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=sF6RnP6g9VMhmpnmJwuveZsyPTLE2YYJxDpaIPmvxYCyywMTFd+Tv3qepsBuquujBZ94nYCwTCDUIWKs1jnyvdTn86dK9ZR/KrtJysAyhzlAR6NjbADL6Mb73ggFq356Zyu04ERPF+5muvOIMYvNM7ipWEg8TVmuihJ2zCIyZUU= Received: by 10.90.54.4 with SMTP id c4mr7226416aga.1164231085261; Wed, 22 Nov 2006 13:31:25 -0800 (PST) Received: by 10.90.65.18 with HTTP; Wed, 22 Nov 2006 13:31:25 -0800 (PST) Message-ID: Date: Wed, 22 Nov 2006 22:31:25 +0100 From: "Nikolai Weibull" Sender: nikolai.weibull@gmail.com To: "Peter Stephenson" Subject: Re: Problem with _arguments Cc: "zsh-users@sunsite.dk" In-Reply-To: <200611221039.kAMAdpal021905@news01.csr.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <200611212342.kALNg9m7006648@pwslaptop.csr.com> <200611221039.kAMAdpal021905@news01.csr.com> X-Google-Sender-Auth: 5229beab525cfdbf On 11/22/06, Peter Stephenson wrote: > > Actually, would there be a good way of tricking _arguments into only > > seeing what you want it to see? In this case, it would work fine if > > one could trick it into only seeing the stuff after src, so that it > > would continue completing options. > > There are certainly ways of updating the line, but the trouble is to > find out what you need to do either you're going to be doing some > parsing yourself or running _arguments twice. You can edit words (the > command line) and CURRENT (the index into it), plus it's also possible > in some contexts to tell _arguments to limit the words visible in the > completion that it's calling by the use of enough colons. I find > directly manipulating words and CURRENT less infuriating. This worked out quite well actually. Find is actually incredibly complicated and has a rather horrible interface. Anyway, here's my solution: integer i (( i = index_of_find + 1 )) while [[ $words[i] == -([HLP]|-(help|version)) ]]; do (( i++ )) done while [[ -d $words[i] ]]; do (( i++ )) done words=($words[1,index_of_find] $words[i,-1]) (( CURRENT -= i - index_of_find - 1 )) integer old_words_length (( old_words_length = $#words )) words=(${words:#\\[()\!]}) (( CURRENT -= old_words_length - $#words )) Index_of_find keeps track of the index of -find in the words array. Here's the algorithm: 1. The option -find can be followed by the options -H, -L, or -P to specify how symbolic links are to be dealt with, along with -help or -version, so skip those. [1] 2. After that, any number of directories may follow. [2] 3. Now we know what slice to remove from the words array and we do so. 4. Next we need to remove any \!, any \(, and any \) that may appear in the $words array, as these are used to negate and group expressions and also mess up the command-line processing of _arguments. [3] /Now/ we can call _arguments. This can actually be used in _find as well, and I might submit a patch once I'm done with this completion definition (for mkisofs if that was unclear). Super-happy-fun-thank-yous to Peter and Bart for your suggestions on how to solve this. Your answers are always helpful, insightful, and to the point. Seriously, you guys rock. But it's also a bit sad that you seem to be the only two that posses the necessary knowledge of Zsh to answer these questions (and are active on these two mailing lists). I hope my shell-skills will reach your level some day. super-happy-fun-time-nikolai [1] Of course, if -help or -version is in the command line, completion has ended already (they're defined as '(- *)-help...' and '(- *)-version...'), so this is superfluous, but at least it's complete. [2] Checking that they're directories is also a bit stupid, and should perhaps only check that they don't match an option, for example, [^-]*, but I figured this was a bit more expressive. [3] This could technically be limited to only the slice [i,-1], but I wanted to keep things simple.