zsh-workers
 help / color / mirror / code / Atom feed
* Completion for `sub-options'
@ 2003-04-19 16:39 Istvan Sebestyen
  2003-04-21  9:03 ` Oliver Kiddle
  0 siblings, 1 reply; 2+ messages in thread
From: Istvan Sebestyen @ 2003-04-19 16:39 UTC (permalink / raw)
  To: zsh-workers

Hello there!

I began to write a zsh completion for a little httpd. I saw then, that it isn't as easy as i thought, because the program hasn't regular options, it has `sub-options', too. The example would be:

zsh%  program --errordoc 404=/var/www/foobar.html

First it should make the completion for the error code, what is trivial to make (401, 404, etc...). The second thing, it should put a `=' after the error-code completion and then look for  _files -g '*.(html|htm|php|etc...)'. 

I looked into several completions of programs that have such options, too (i.e. like mount), but i couldn't make it work.  If someone can give me an easy solution for this problem, I would be very thankful.

Thanks,
Istvan Sebestyen


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

* Re: Completion for `sub-options'
  2003-04-19 16:39 Completion for `sub-options' Istvan Sebestyen
@ 2003-04-21  9:03 ` Oliver Kiddle
  0 siblings, 0 replies; 2+ messages in thread
From: Oliver Kiddle @ 2003-04-21  9:03 UTC (permalink / raw)
  To: Istvan Sebestyen; +Cc: zsh-workers

Istvan Sebestyen wrote:
> 
> I began to write a zsh completion for a little httpd. I saw then, that
> it isn't as easy as i thought, because the program hasn't regular
> options, it has `sub-options', too. The example would be:
> 
> zsh%  program --errordoc 404=/var/www/foobar.html
> 
> First it should make the completion for the error code, what is
> trivial to make (401, 404, etc...). The second thing, it should put a
> `=' after the error-code completion and then look for  _files -g
> '*.(html|htm|php|etc...)'.

You need to use compset -P and compset -S to divide the word at the
equals sign:

  local suf expl

  if compset -P '*='; then
    _wanted documents expl 'document' _files -g '*.(html|htm|php)'
  else
    compset -S '=*' || suf=( -S = )
    _wanted values expl 'error number' compadd $suf 401 404 405
  fi

compset -P and compset -S chop off a prefix or a suffix respectively
from being considered by the completion system. So if it successfully
removes an error number from the beginning of the current word it
completes documents. Otherwise it completes error numbers after being
sure to ignore anything after an equals sign.

You could actually use _values for this if you find this simpler:
  _values 'error document' {401,404,405}':document:_files -g "*.(html|htm|php)"'

Though _values is meant for slightly different cases really.

If you're using _arguments to complete the --errordoc option, you may
need to utilise a separate function or a state
('--errordoc:error document:->errordoc') to do this (though you could
use the _values stuff after doubly quoting it).

Oliver


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

end of thread, other threads:[~2003-04-22 12:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-19 16:39 Completion for `sub-options' Istvan Sebestyen
2003-04-21  9:03 ` Oliver Kiddle

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