zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: David Remahl <david@ittpoi.com>
Cc: zsh-workers@sunsite.dk
Subject: Re: Complicated Completions
Date: Tue, 26 Aug 2003 11:11:39 +0200	[thread overview]
Message-ID: <20424.1061889099@gmcs3.local> (raw)
In-Reply-To: <CF1EFB86-D75A-11D7-982B-0003930A2D56@ittpoi.com>

David Remahl wrote:

> I have spent some time trying to get to know the completion system. My  
> aim is to create completion functions for some of the useful and  
> surprisingly well-documented command line tools specific to Mac OS X  
> (hdiutil, diskutil, defaults, SystemStarter, ditto to mention a few).  

Sounds good.

> The thing is, some of them use rather peculiar and complex command line  
> syntaxes, so creating useful completions is quite a challenge.

There's a few other commands that follow a similar scheme. _sccs might
be a better example than _ifconfig. Also worth looking at are _xauth
and _cdcd which are simpler and _cvs which is more complicated.

> I will begin by describing the command line syntax of hdiutil, using  
> snippets from the man page.
> 
> SYNOPSIS
>       hdiutil verb [options]

Can any options appear between hdiutil and the verb? If so, begin with
an _arguments for those options finishing with a '*:: :->verbs' rule to
complete the sub commands in a state.

> Verb is one of the following:
> 	attach, detach, verify, create, convert, burn, help, info, load,  
> checksum, eject (synonym for detach), flatten, unflatten, imageinfo,  
> mount (synonym for attach), mountvol, unmount, plugins,  
> internet-enable, resize, segment, partition, makehybrid, pmap

Just completing those should be straight-forward. If you can use
_describe to give descriptions for them, that is better. For the
synonyms, give them the same description, e.g:
  {eject,detach}':description'
in zsh 4.1, they will then be grouped together.

What does the help verb output? You might be able to parse this to get
descriptions. If you get a recent _cvs from CVS, it does this.

Then follow the pattern of one of the examples:
  service="$words[1]"
  curcontext="${curcontext%:*}-$service:"

This puts the verb into $service and into the zstyle context (so you
will have, e.g. hdiutil-attach in the command part of the zstyle
context). Then, just have a case statement for each possible verb:
  case $service in
    attach)
      ...

> The set of allowed options depends on the sub command (verb). All verbs  
> accept the following optional options (duh), all mutually exclusive:
> 	-verbose
> 	-quiet
> 	-debug

Stick the _arguments specifcations for them in an array at the
beginning and include the array in all later calls to _arguments. e.g:

  args=(
    '(-quiet -debug)-verbose'
    '(-verbose -debug)-quiet'
    '(-quiet -verbose)-debug'
  )

then later, _arguments "$args[@]" \
The lists in parenthesis at the start of the specifications specifies
that they are mutually exclusive.

> Many verbs accept these options:
> 	-plist
> 	-srcimagekey <key>=<value>
> 	-tgtimagekey <key>=<value>
> 	-encryption [crypto method]
> 	-stdinpass
> 	-passphrase password
> 	-shadow [shadow file]

Again, put the specifications for those options in an array and use the
array with those sub-commands that need them.

> Many verbs take additional options that are specific to that verb. For  
> example, convert takes the following additional arguments / options:
> Required:

Specify these options in each branch of the case statement.

> Several commands  
> (attach|verify|compact|convert|burn|checksum|chpass|*flatten|fsid|image- 
> info|internet-enable|resize|segment|partition|pmap) take exactly one  
> filename argument - of a .dmg file. That corresponds to imagefile in  
> teh above convert example.

So they need an _arguments specification that looks like:
  '1:file:_files -g "*.dmg"'

Hope that helps

Oliver


  reply	other threads:[~2003-08-26  9:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-08-26  0:18 David Remahl
2003-08-26  9:11 ` Oliver Kiddle [this message]
2003-08-28 19:50   ` David Remahl
2003-08-29  9:27     ` Oliver Kiddle

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=20424.1061889099@gmcs3.local \
    --to=okiddle@yahoo.co.uk \
    --cc=david@ittpoi.com \
    --cc=zsh-workers@sunsite.dk \
    /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).