zsh-users
 help / color / mirror / code / Atom feed
From: luc <luc.lists@gmail.com>
To: Zsh Mailinglists <zsh-users@zsh.org>
Subject: Re: completion function for system_profiler (OS X)
Date: Thu, 6 Feb 2014 02:50:34 +0100	[thread overview]
Message-ID: <20140206015034.GA4321@mbp.localdomain> (raw)
In-Reply-To: <FC051A8C-3670-4DA6-A981-895E45DD344C@kba.biglobe.ne.jp>

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

Hello Jun,

> You can simply use '*:message:action' as a spec for _arguments.
This works perfectly.
> 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.
I am now hardcoding the data types into the array as the call for
`system_profiler -listDataTypes` is taking a lot of time sometimes.  I
think this list hardly ever changes (in new versions of OS X?).

I will attach my "final" version again.  Is it reasonalble (or desired)
to commit this upsream?

Thank you for your help
Lucas

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

#compdef system_profiler

typeset -A opt_args
local context state state_descr line
local -a _data_types

# TODO: Should this be static?  Calling `system_profiler -listDataTypes` takes
# about 0.07-0.08 secs on my machine.  Does this list ever change (between
# different versions of OS X)?
_data_types=( SP{AirPort,Applications,Audio,Bluetooth,Camera,CardReader,Component,ConfigurationProfile,DeveloperTools,Diagnostics,DisabledSoftware,DiscBurning,Displays,Ethernet,Extensions,FibreChannel,FireWire,Firewall,Fonts,Frameworks,Hardware,HardwareRAID,InstallHistory,Logs,ManagedClient,Memory,Network,NetworkLocation,NetworkVolume,PCI,ParallelATA,ParallelSCSI,Power,PrefPane,Printers,PrintersSoftware,SAS,SPI,SerialATA,Software,StartupItem,Storage,SyncServices,Thunderbolt,USB,UniversalAccess,WWAN}DataType )
# the dynamic alternative is:
#_data_types=( ${${(f)"$(_call_program path 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]' \
  '(-listDataTypes -usage)*:data type:'"($_data_types)"

  reply	other threads:[~2014-02-06  3:31 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.
2014-02-06  1:50   ` luc [this message]
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=20140206015034.GA4321@mbp.localdomain \
    --to=luc.lists@gmail.com \
    --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).