zsh-users
 help / color / mirror / code / Atom feed
* completion function for system_profiler (OS X)
@ 2014-02-05 12:00 luc
  2014-02-05 17:23 ` Jun T.
  0 siblings, 1 reply; 5+ messages in thread
From: luc @ 2014-02-05 12:00 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 1101 bytes --]

Hello list menbers,

I'm writing a completion function for the OS X command system_profiler.  (I
did't find one preinstalled with `find $fpath -name _system_profiler` so I
assume there isn't one already)

The manpage for system_profiler says:
> SYNOPSIS
>      system_profiler [-usage]
>      system_profiler [-listDataTypes]
>      system_profiler [-xml] dataType1 ... dataTypeN
>      system_profiler [-xml] [-detailLevel level]

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.

Note that the man page is not correct at one point:  It is possible to specify
both -detailLevel and some dataTypes.  For example `system_profiler
-detailLevel mini SPAirPortDataType` differs from `system_profiler -detailLevel
full SPAirPortDataType`

Thank you for any help or hints
Lucas

[-- Attachment #2: _system_profiler --]
[-- Type: text/plain, Size: 762 bytes --]

#compdef system_profiler

typeset -A opt_args

local context state line

local -a _data_types

# TODO: Should this be static?  Calling `system_profiler -listDataTypes` takes
# about 0.07-0.08 sec.  Does this list ever change (between different versions
# of OS X)?
_data_types=$(_call_program path system_profiler -listDataTypes 2>/dev/null)

_arguments \
  '(-listDataTypes -detailLevel -timeout -usage)-usage' \
  '(-listDataTypes -usage)-xml[generate xml output]' \
  '(-listDataTypes -xml -detailLevel -timeout -usage)-listDataTypes[lists the available datatypes]' \
  '(-listDataTypes -usage)-detailLevel[level of detail for the report]:detail level:(mini basic full)' \
  '(-listDataTypes -usage)-timeout+[maximum time to wait in seconds]' \
  && return 0

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-02-07  1:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-05 12:00 completion function for system_profiler (OS X) luc
2014-02-05 17:23 ` Jun T.
2014-02-06  1:50   ` luc
2014-02-06  9:41     ` Peter Stephenson
2014-02-06 15:44     ` Bart Schaefer

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).