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
- X-seq: zsh-workers 42815
- From: Doron Behar <doron.behar@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Completion: make certain options' arguments complete according to arguments given to previous options
- Date: Wed, 23 May 2018 22:30:32 +0300
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mail-followup-to:mime-version :content-disposition:user-agent; bh=EF4k6I3MupPsecqBHA4sbRrOytKS/913at+kSke2M2A=; b=eKzqrPVENxYRfW8d5o1k3/NgveXbFUwfBr1Ix+dChdhMbbsl1APE6Ss/3HaIOb4kmd fBojNYGQ8DlJqoWQyh1jrFo7vUYlvcCOg9MwcOM3/oLNUKek/kzEK836RYAWRdd08QhS CqtnqRBJADXd4nV7vLLeDpabYD1HqeiaA1OaXt/WHHXUnwAi2zcKQoF1E4LGfqatrZlP UVMhT5ls0tzAypYzV5/b/nTB6lhGEpqaxoDi6rLd7OGPJRHSuNWzsM5qvJnJL1cdxsHz oLbBBq7vUAv3Y0dlQY7siTn3qBI2Y7KEZ6RSsO8AnW9h2+TJKanCk9D4fhwvfAx5bLiP qeWQ==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mail-followup-to: zsh-workers@xxxxxxx
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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