From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6505 invoked by alias); 7 Nov 2013 04:18:05 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 18112 Received: (qmail 27708 invoked from network); 7 Nov 2013 04:17:59 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 From: Bart Schaefer Message-id: <131106201745.ZM20201@torch.brasslantern.com> Date: Wed, 06 Nov 2013 20:17:45 -0800 In-reply-to: <527AE8BF.6090706@gmail.com> Comments: In reply to John "Re: ordering of file-patterns completions" (Nov 6, 6:11pm) References: <527A5F11.2080701@gmail.com> <131106080319.ZM19160@torch.brasslantern.com> <527AE8BF.6090706@gmail.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: ordering of file-patterns completions MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Nov 6, 6:11pm, John wrote: } } > doesn't quite generalize if there may be options (words starting with } > a hyphen) between the command name and the first file. If that is the } > case, you'll need to do some pre-processing of $words before calling } > _arguments to determine which position to reference instead of [2]. } } Yeah, unfortunately I do. I was using _arguments to process those, and } then zstyle to deal with the files. But I'm not quite understanding how } to do what you're describing to pre-process them instead of using } _arguments. How complicated this needs to be depends on what might appear in the words preceding the first file. If there's nothing but options, for example, then you can probably do: local first_file=$(( ${words[(I)-*]} + 1 )) which says to start from the end of the array and look backward to find the index of the first word that DOES start with a hyphen, and then add one to it. Or, if there might be file names that start with hyphen, then: local first_file=$(( ${${words[2,-1]}[(i)[^-]*]} + 1 )) which says "in the array formed by the second through last elements of the words array, report the index of the first element that does not begin with a hyphen" and then add one to compensate for starting at 2. If there are options that might take arguments, so some of the words before the first file might not begin with hyphen, then you'll have to try something else; perhaps: local -a opts set -- $words[2,-1] zparseopts -a opts ... local first_file=$(( $#opts + 2 )) where "..." is a description of the options. Yeah, this kinda sucks because you have to describe the same options to both zparseopts and _arguments. In any case, once you're done computing first_file: _arguments $stuff_describing_options \ '1:The first file:_files -g "XXX.*"' \ '*:All other files:_files -g "*.${words[first_file]:x}"'