From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14159 invoked by alias); 5 Feb 2014 17:23:52 -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: 18401 Received: (qmail 17097 invoked from network); 5 Feb 2014 17:23:46 -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-Biglobe-Sender: Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 7.1 \(1827\)) Subject: Re: completion function for system_profiler (OS X) From: "Jun T." In-Reply-To: <20140205120058.GA85309@mbp.localdomain> Date: Thu, 6 Feb 2014 02:23:42 +0900 Content-Transfer-Encoding: quoted-printable Message-Id: References: <20140205120058.GA85309@mbp.localdomain> To: zsh-users@zsh.org X-Mailer: Apple Mail (2.1827) 2014/02/05 21:00, luc wrote: > My problem is the third posibility: I do not know how to tell the = completion > system to allow several dataTypes after the command. I store the = dataTypes in > an array which I populate with `system_profiler -listDataTypes`. How = can I > tell zsh that any of these strings may follow in any order several = times, > unless -usage or -listDataTypes is given? My code so far is attached. You can simply use '*:message:action' as a spec for _arguments. This can complete any number of normal arguments. As the 'action', you can use '(val1 val2 ...)' as you have already used for the option -detailLevel. So the simplest possibility may be the following: ----------- #compdef system_profiler local context state state_descr line=20 typeset -A opt_args local -a _data_types _data_types=3D( ${${(f)"$(_call_program datatypes system_profiler = -listDataTypes 2>/dev/null)"}[2,-1]} ) _arguments \ '(- *)-usage' \ '(- *)-listDataTypes[lists the available datatypes]' \ '(-listDataTypes -usage)-xml[generate xml output]' \=20 '(-listDataTypes -usage)-detailLevel[level of detail for the = report]:detail level:(mini basic full)' \ '(-listDataTypes -usage)-timeout+[maximum time to wait in seconds]' \ '*:data type:'"($_data_types)" ----------- Output from $(system_profiler -listDataTypes) contains a header line, which is removed by ( ${$(f)"$(command)"}[2,-1]} ). You are using _call_program so a user can replace the command by using zstyle. But the 1st line of the output from the user-specified command will also be removed.