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

Re: dynamic file completion



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