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



Cool!

Is there a way to know if a certain argument was given? I'm talking
about the case where this argument doesn't accept an argument.

On Thu, May 24, 2018 at 10:57:23AM +0900, Jun T wrote:
> 
> > 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