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

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



Hello zsh-users,

I would like to write a completion function for a command and I need
that some of the options' arguments will be completed in awareness to
arguments given to previous options. I've no idea if this is possible
and if so, where to start?

Allow me to explain:

Let's say the command is called `cmd`. `cmd` accepts the options
`--datadir=` and `--template=` which both accept a single argument.

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.

I want the `--template=` option's argument to be completed with a file
from the default data directory. But, if the `--datadir` is specified, I
want the `--template=` option's argument to be completed with a file
from the specified data directory.

Is it possible with the way zsh completion functions are implemented?
Essentially it'll look like that:

    _cmd_datadir(){
    	# I need to get the choice from this completion into a
    	# temporary file or something like that, perhaps in $data_dir
    	_files -/
    }

    _cmd_template(){
    	if [[ -z $datadir ]]; then
    		_files -W $default_data_dir
    	else
    		_files -W $data_dir
    	fi
    }



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