From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19510 invoked by alias); 7 Nov 2013 06:30:13 -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: 18113 Received: (qmail 2468 invoked from network); 7 Nov 2013 06:30:06 -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=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, T_TO_NO_BRKTS_FREEMAIL autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=rbs0Yz5aD0eM0Et9mz3Rrsb+QW176Pw0U+KOoCGprtM=; b=XvIQBxK+DKF6Y+2RoZRDCccZAU7/jicKl2g5arMyqsBvV3G6dkd8+PXuMR9Lgr0wfq iYHM6Nn6deIcBSyrQ2S7LG6Mugcq4duBaU3U1ixDDnRAsoSsyoaO2Ypsw6gpAb3rCXvi yJemXLKH2lbUiL1mUWMWExOJJovHKB20bAiEDSoIFAvIAngE+2+BxZk7S62GowHE2+3/ lfxvlnUDVCgESRsROMFM0wCC90APp7FR651FG7hXtCuZ75nP2mrFZdn3118/GPl3Ax1w objT6xAyecZ1dQ2hkdLOIkYCVj+MAPvoCJQNIKeD/rVVZF6HrwZB6iNgMsbg2gBUbL84 X7CA== X-Received: by 10.50.21.6 with SMTP id r6mr934839ige.44.1383805803604; Wed, 06 Nov 2013 22:30:03 -0800 (PST) Message-ID: <527B336A.40506@gmail.com> Date: Wed, 06 Nov 2013 23:30:02 -0700 From: John User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: zsh-users@zsh.org Subject: Re: ordering of file-patterns completions References: <527A5F11.2080701@gmail.com> <131106080319.ZM19160@torch.brasslantern.com> <527AE8BF.6090706@gmail.com> <131106201745.ZM20201@torch.brasslantern.com> In-Reply-To: <131106201745.ZM20201@torch.brasslantern.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 11/6/13, 9:17 PM, Bart Schaefer wrote: > 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. > The first one nearly does it, but seems to be confused when there are no options at all. That is, it works fine as long as there is a --opt1, but if there isn't, the *: portion says it's completing the right thing, but then lists all the files rather than the matching one: % yes XXX. Completing XXX file XXX.0 XXX.bogus XXX.bogus3 XXX.1 XXX.bogus2 XXX.bogus4 % yes --opt1 XXX.0 XXX-YYY.0 % yes XXX.0 XXX Completing XXX extra files XXX-YYY.0 XXX.0 XXX.bogus XXX.bogus3 XXX-YYY.1 XXX.1 XXX.bogus2 XXX.bogus4 This is with: #compdef yes local first_file=$(( ${words[(I)--*]} + 1 )) _arguments \ '--opt1[desc1]' \ '--opt2[desc2]' \ '1:XXX file:_files -g "*XXX.*"' \ '*:XXX extra files:_files -g "*XXX-*.${words[first_file]:e}"' I ended up adding: if [[ $first_file -lt 2 ]]; then first_file=2 fi And that fixed it. Not realizing that the array was 1-based threw me for a bit. I also changed the :x to a :e, as :x just gave me an error, and :e matched the description of what I think you had meant. Thanks! John