Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Completion for `sub-options'

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)'
    compset -S '=*' || suf=( -S = )
    _wanted values expl 'error number' compadd $suf 401 404 405

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


Messages sorted by: Reverse Date, Date, Thread, Author