Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: dynamic file completion
- X-seq: zsh-users 10038
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: dynamic file completion
- Date: Fri, 17 Mar 2006 17:34:56 +0000
- In-reply-to: <20060317170315.GA19760@xxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20060317170315.GA19760@xxxxxxxxx>
Andy Spiegl wrote:
> It basically works but I'd like to add the feature that the filenames to be
> completed are from a specific directory (without the path) and that this
> directory can be overriden with the cmdline parameter --dir (or --criddir).
You need the -W argument to _files; I'd suggest using "_path_files -W
<dir>", since going directly to _path_files removes some smart behaviour
in _files you don't want in this case.
> So somehow the function has to dynamically change the list of possible
> files, right? I have no idea how to do that nicely. Please help!
So you need to use your specific directory, but override it if there's a
--dir. You'll need to check if there's a --dir on the command line
already and grab it's argument. You need something like:
local dir=${words[(r)--dir=*]##--dir=}
if [[ -z $dir ]]; then
integer dirind=${words[(i)--dir]}
if (( dirind )); then
dir=$words[dirind+1]
fi
fi
if [[ -z $dir ]]; then
dir="default directory"
fi
> ':cmds: compadd ${${(f)"$(gigaset --commands)"}%%[[:space:]]##--*}' \
> '*:cridfiles:_cridfiles'
>
> For the last line to work I had to write another file "_cridfiles":
> (How can I include this definition in the first file?)
The most general way to avoid a separate function is the "->state"
action for _arguments; look in the zshcompsys manual page or various of
the more complicated functions (you need to make some variables local to
use it). It sets the variable compstate which you can test to see if
it's in the particular state.
In your case, it might be possible to specify the description some
other way, so you could put the _path_files as the action, but I'm not
sure how.
--
Peter Stephenson <pws@xxxxxxx> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
To access the latest news from CSR copy this link into a web browser: http://www.csr.com/email_sig.php
Messages sorted by:
Reverse Date,
Date,
Thread,
Author