From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15461 invoked by alias); 28 Jul 2014 20:19:00 -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: 18994 Received: (qmail 25524 invoked from network); 28 Jul 2014 20:18:48 -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 X-Originating-IP: [86.6.157.246] X-Spam: 0 X-Authority: v=2.1 cv=IZoJWAaa c=1 sm=1 tr=0 a=BvYiZ/UW0Fmn8Wufq9dPrg==:117 a=BvYiZ/UW0Fmn8Wufq9dPrg==:17 a=NLZqzBF-AAAA:8 a=KleuIgBjfgoA:10 a=uObrxnre4hsA:10 a=IkcTkHD0fZMA:10 a=h7qRFFynqd610J-28UUA:9 a=QEXdDO2ut3YA:10 a=XkS7lJdTqAAA:10 Date: Mon, 28 Jul 2014 21:12:47 +0100 From: Peter Stephenson To: zsh-users@zsh.org Subject: Re: completion: _normal after argument Message-ID: <20140728211247.09469e0d@pws-pc.ntlworld.com> In-Reply-To: References: X-Mailer: Claws Mail 3.8.0 (GTK+ 2.24.7; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Mon, 28 Jul 2014 12:16:10 +0000 (UTC) Martin Vaeth wrote: > for some scripts I am currently writing some completion functions. > The syntax of the call should be >=20 > foo [lots of complicated options] CMD [shell-command with options] >=20 > Naturally, since the options can be treated with _arguments in > a standard way, I want to use something like >=20 > _arguments -C -s -S -A '-*' : \ > --optA=3D.... \ > --optB... \ > -q... \ > ... > '1:command:->cmds' \ > '*::command:->normal' >=20 > It is clear to me what to do in case $state =3D=3D cmds > But what to do in case $state =3D=3D normal? > Essentially, I want to call of course _normal > (after cutting the "options+CMD" part from the words array and > decreasing the CURRENT parameter correspondingly). > But how to find where the "options+CMD" part has finished? You can use _arguments -n. With the option -n, _arguments sets the parameter NORMARG to the position of the first normal argument in the $words array, i.e. the position after the end of the options. If that argument has not been reached, NORMARG is set to -1. The caller should declare `integer NORMARG' if the -n option is passed; otherwise the parameter is not used. Supposedly you don't even need to do that, however: *:::message:action This describes how arguments (usually non-option argu=E2=80=90 ments, those not beginning with - or +) are to be com=E2=80=90 pleted when neither of the first two forms was provided. Any number of arguments can be completed in this fashion. With two colons before the message, the words special array and the CURRENT special parameter are modified to refer only to the normal arguments when the action is executed or evaluated. With three colons before the mes=E2=80=90 sage they are modified to refer only to the normal argu=E2=80=90 ments covered by this description. I have a feeling I've had trouble with that in the past though (and, obviously, no one in their senses would try to understand _arguments). pws