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

Re: Completion: make certain options' arguments complete according to arguments given to previous options



> 2018/05/24 4:30, Doron Behar <doron.behar@xxxxxxxxx> wrote:
> 
> If the `--datadir=` option is used, `cmd` knows that templates should be
> looked for in the specified directory only. If `--datadir` isn't
> specified, there is a default data directory `cmd` looks for templates
> in it.

You can use the associative array 'opt_args' to find the options and their
args on the command line so far:


#compdef cmd
local curcontext="$curcontext" state state_descr line ret=1
typeset -A opt_args

_arguments -C : \
  '--datadir=[specify data directory]:data directory:_files -/' \
  '--template=[specify template file]:template file:->template' && ret=0

case $state in
template)
  local data_dir=$opt_args[--datadir]
  [[ -z $data_dir ]] && data_dir=/etc	# default data directory
  _files -W data_dir && ret=0
  ;;
esac

return ret






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