zsh-users
 help / color / mirror / code / Atom feed
From: "Jun T." <takimoto-j@kba.biglobe.ne.jp>
To: zsh-users@zsh.org
Subject: Re: completion function for system_profiler (OS X)
Date: Thu, 6 Feb 2014 02:23:42 +0900	[thread overview]
Message-ID: <FC051A8C-3670-4DA6-A981-895E45DD344C@kba.biglobe.ne.jp> (raw)
In-Reply-To: <20140205120058.GA85309@mbp.localdomain>


2014/02/05 21:00, luc <luc.lists@gmail.com> 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 
typeset -A opt_args
local -a _data_types

_data_types=( ${${(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]' \ 
  '(-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.


  reply	other threads:[~2014-02-05 17:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-05 12:00 luc
2014-02-05 17:23 ` Jun T. [this message]
2014-02-06  1:50   ` luc
2014-02-06  9:41     ` Peter Stephenson
2014-02-06 15:44     ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=FC051A8C-3670-4DA6-A981-895E45DD344C@kba.biglobe.ne.jp \
    --to=takimoto-j@kba.biglobe.ne.jp \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).