From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13987 invoked by alias); 14 Mar 2012 18:37:35 -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: 16882 Received: (qmail 18936 invoked from network); 14 Mar 2012 18:37:33 -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.6 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED,RCVD_IN_DNSWL_LOW, T_DKIM_INVALID autolearn=no version=3.3.2 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 209.85.160.171 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=2w99opR5oYXHQZWUDmccYEaKZzHA4JwIl06RgxKrecE=; b=oDS8DthA8ukijMzeeLqiQYb8BeXGjBw/F6aWP3Mg6Obitdo61Kp/ad3j3RjZQdbeCa JfL9v/ORgrAuHH9AS/uiKGmxd2MLAScJ0ydtnGPBgPNXKqARP/rPRkQsX8t7tRxk8+PO tBLbE581MjbCJ+a35jXlqpfqqM+SQ4cTdYDlXTJjvcq8TZJH7RbEZEpQ8FFztPXzUQDz iiAaOnC6yawPMEjJkxSh/U+3RhXfZZMV8Vh/PKbXC1JRIldy9QcBIIG+WnhJoTrYkDoo G88l/vAsJbOsxSjScbvFlyIH3T1p1c6cSehBTbB6GQaE62JW6b+pzrMn/JyCz+Pf73gX 2hDQ== MIME-Version: 1.0 In-Reply-To: References: Date: Wed, 14 Mar 2012 19:30:16 +0100 Message-ID: Subject: Re: Putting options after tasks From: Mikael Magnusson To: =?UTF-8?Q?Jesper_Nyg=C3=A5rds?= Cc: zsh-users@zsh.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 2012/3/14 Jesper Nyg=C3=A5rds : > I am trying to write a completion function for gradle, and face some > problems regarding the order of options and tasks. > > Below I have simplified my approach as much as possible, in order to > explain my problem clearly. The basis for this is originally the > gradle completion from oh-my-zsh. > > gradle can take any number of options (long options starting with > "--") and tasks (with no prefix). In my example below, I have boiled > this down to two options ("--info" and "--stacktrace"), and two tasks > ("build" and "clean"). > > These options and tasks can come in any order, so the following > command lines would all be valid: > gradle clean build > gradle --info clean build --stacktrace > gradle --stacktrace --info clean build > etc > > My problem is this: the completion below works fine and completes both > options and tasks, but once I have at least one task on the command > line, it no longer completes for options. So, for example, if I have > "gradle build --i" and press , I get no suggestions, whereas > "gradle bu" gives "gradle build", and "gradle --i" gives > "gradle --info". > > What do I have to do to make it possible to complete options after tasks? Replace :: with : and it will "work", however there are some other problems with the code you wrote. You modify the $commands array without making it local, you also forget to local a few other things. The following seems to work fine (i also put it in an autoloaded _gradle file in $fpath): #compdef gradle local ret=3D1 state state_descr line local curcontext=3D"$curcontext" local -A opt_args local -a commands _arguments -C \ '--info[Log at the info level]' \ '--stacktrace[Display stacktrace on error]' \ '*:command:->command' \ && ret=3D0 if [[ $state =3D=3D command ]]; then commands=3D( "clean:Clean the project" "build:Build the project" ) _describe -t commands 'gradle commands' commands && ret=3D0 fi return ret --=20 Mikael Magnusson