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

Re: 3.0.x completion on commands w/ common prefix



On Nov 1, 12:05pm, Phil Pennock wrote:
> Subject: 3.0.x completion on commands w/ common prefix

> I have a whole bunch of commands which all start with a common prefix.
> I'd like to set a standard tab-completion for any command starting with
> that prefix, no matter where in $PATH they are.
> 
> The specifics:
>  * array $sshhosts with list of hostnames
>  * commands all start remote_

You want something along the lines of

	compctl -Tx 'W[0,remote_*] p[1,-1]' -k sshhosts

Which says that if the word in command position matches the pattern
"remote_*" and you are completing in any of the argument positions, then
use the array sshhosts.  Otherwise (part of the definition of -T, but
see below) fall through to normal completion for the command.

You can change the range specified with p[] to change where sshhosts is
used, add other extended-completion patterns, etc.  Note that you get only
one compctl -T, so if you have other commands that you want to pattern-
match in this way, you have to add more `W[0,...]' alternatives to the -x
set, e.g.

	compctl -Tx 'W[0,remote_*] p[1,-1]' -k sshhosts \
		-   'W[0,x*] c[-1,-display]' -k x11displays

and so on.

In 3.1.9 (and at some point after 3.1.5, but I forget exactly when) you
need to append `-tn' to the end of the compctl to specify the fallthrough
behavior (the default changed).



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