From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27219 invoked by alias); 6 Nov 2013 16:03:51 -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: 18101 Received: (qmail 2109 invoked from network); 6 Nov 2013 16:03:34 -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: <131106080319.ZM19160@torch.brasslantern.com> Date: Wed, 06 Nov 2013 08:03:19 -0800 In-reply-to: <527A5F11.2080701@gmail.com> Comments: In reply to John "ordering of file-patterns completions" (Nov 6, 8:24am) References: <527A5F11.2080701@gmail.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: Zsh-Users List Subject: Re: ordering of file-patterns completions MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Nov 6, 8:24am, John wrote: } } I have a tool which needs one file-patterns for the first file matched, } then the second and the rest should be of a different file-patterns. I } don't see a way to do this. You probably want to write a custom completer with the _arguments utility function, and to leave file-patterns unspecified. _foo() { _arguments '1:The first file:_files -g "XXX.*"' \ '*:All other files:_files -g "*.${words[2]:x}"' } compdef _foo foo Here "1:" refers to the first argument (after skipping the command name and any option flags) whereas "$words[2]" refers to the second word of the entire command line (first word after the command name), so this 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]. (You can skip the "compdef" command if you put the body of _foo in a file named _foo in a directory referenced in your $fpath, and begin that file with the line "#compdef foo".) } Are there any examples of something similar to this around? There are lots of examples of using _arguments in the default set of completion functions. If there is a standard tool that you know of that accepts arguments something like your custom one, try looking at the completion function for that. You can usually find the name of that function by looking at ${_comps[command-name-here]}.