From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22301 invoked by alias); 24 Nov 2013 19:01:24 -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: 18163 Received: (qmail 23725 invoked from network); 24 Nov 2013 19:01:07 -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: <131124110109.ZM26202@torch.brasslantern.com> Date: Sun, 24 Nov 2013 11:01:09 -0800 In-reply-to: <52921EF8.8080909@gmail.com> Comments: In reply to John "compsys: argument with pre-requisite argument" (Nov 24, 8:44am) References: <52921EF8.8080909@gmail.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: compsys: argument with pre-requisite argument MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Nov 24, 8:44am, John wrote: } Subject: compsys: argument with pre-requisite argument } } what I want is something like: } } _arguments \ } '-D+[debug]:debug level(0 1)' \ } '--opt1[opt1 description]' \ } '--special[special case]' \ } '-a[special case a]' \ } '-b[special case b]' } } such that -a and -b are only available if --special was already } specified, but --opt1 and -D are always available for completing. My first thought was that this is actually similar to what happens in _sh for zsh completions (about which we had a thread on zsh-workers earlier this year). Crudely, two calls to _arguments something like: _arguments \ '-D+[debug]:debug level:(0 1)' \ '--opt1[opt1 description]' \ '--special[special case]' local ret=$? if [[ "${words[1,CURRENT]}" == *" --special"* ]] && _arguments \ '-a[special case a]' \ '-b[special case b]' then ret=0 fi return ret (I added the missing colon in the -D spec.) However, making two calls to _arguments can sometimes have side-effects. So here's a different approach which makes only one call to _arguments: local ifspecial='!' [[ "${words[1,CURRENT]}" = *" --special"* ]] && ifspecial='' _arguments \ '-D+[debug]:debug level:(0 1)' \ '--opt1[opt1 description]' \ '--special[special case]' \ $ifspecial'-a[special case a]' \ $ifspecial'-b[special case b]' Or a different twist on the same: local -a special [[ "${words[1,CURRENT]}" = *" --special"* ]] && special=( '-a[special case a]' '-b[special case b]' ) _arguments \ '-D+[debug]:debug level:(0 1)' \ '--opt1[opt1 description]' \ '--special[special case]' \ $special In most cases these three will be equivalent, so pick whichever one you find easiest to understand / maintain.