Zsh Mailing List Archive
Messages sorted by:
Re: trying to learn zstyle
- X-seq: zsh-users 2799
- From: Peter Stephenson <pws@xxxxxxxxxxxxxxxxxxxxxxxx>
- To: ZSH Mail List <zsh-users@xxxxxxxxxxxxxx>
- Subject: Re: trying to learn zstyle
- Date: Wed, 22 Dec 1999 23:08:12 +0000
- In-reply-to: "Shao Zhang"'s message of "Wed, 22 Dec 1999 11:49:28 +1100." <19991222114928.A29277@localhost>
- Mailing-list: contact zsh-users-help@xxxxxxxxxxxxxx; run by ezmlm
As a preface: the stuff discussed below is new since 3.1.6. I should
perhaps explain to zsh-users readers not on zsh-workers that the latest
development version of the shell is now available on the archive and
mirrors in the `development' subdirectory.
Shao Zhang wrote:
> I am trying to learn zstyle to do command completion, but I am
> very very confused how everything works after reading the doc
> and trying out.
It's quite complicated. I'm working on the chapter of my zsh guide which
deals with completion to try to help.
> I have the following lines in my .zshrc:
> zstyle ':completion:*:hello:*:hosts' hosts $HOSTS
> zstyle ':completion:*:mtvp:*:hosts' hosts $HOSTS
> zstyle ':completion:*:telnet:*:hosts' hosts $HOSTS
> But all of them behaves differently.
> hello [TAB] gives me a completion of list of files in my current
> mtvp [TAB] give me a completion of -display -geometry
(It's not part of your question, but if you want to use the same list of
hosts in all contexts, you can set
zstyle '*' hosts $HOSTS
which simplifies things a bit.)
The style `hosts' just gives values for cases where hosts are completed ---
it doesn't say where hosts are to be completed. You can think of styles
just as a sort of shell parameter, but (as you realised) with the ability
to have different values in different contexts. You need to tell the
system that the command `hello' has to take hosts as arguments. The
easiest way to do it is this (after loading completion, of course):
compdef _hosts hello mtvp
> telnet behaves the way I want, which gives me a list of hosts
> defined in $HOSTS.
That's because it's already set up to use hosts. You can check this by
which gives `_telnet' (surprised?). If you look in the function _telnet,
the hosts handling is buried inside the `combination '' hosts-ports-users'
We ought to add things like the handling function to the output of ^Xh
(that's what tells you the context you're completing in). It helps in this
case a bit, because if you did it with `hello' you'd have got:
tags in context `:complete::hello:':
which would have told you that the only valid tags were files and
all-files, but not hosts.
Peter Stephenson <pws@xxxxxxxxxxxxxxxxxxxxxxxx>
Messages sorted by: