Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: how to use tags in zsh completion system
- X-seq: zsh-users 26051
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- Subject: Re: how to use tags in zsh completion system
- Date: Fri, 4 Sep 2020 19:23:29 +0000
- Archived-at: <https://zsh.org/users/26051>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-users/2020-09/20200904192329.08f436ea%40tarpaulin.shahaf.local2>
- Authentication-results: zsh.org; iprev=pass (out3-smtp.messagingengine.com) smtp.remote-ip=66.111.4.27; dkim=pass header.d=daniel.shahaf.name header.s=fm1 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm3 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none
- Cc: Ahmad Ismail <ismail783@xxxxxxxxx>, zsh-users@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=date:from:to:cc:subject:message-id :in-reply-to:references:mime-version:content-type :content-transfer-encoding; s=fm1; bh=qBhlh02LERehkSuLwVQsD1xp3N KY8ekZWjOdYAGQ9NE=; b=aPx+87BgbfteOqAMlOMnHlrZEiibz49dXyS+ttmvG1 eiTSxJQmRjAzfQwK0W5sKf21fVfEJuOW3WIWqhpyk5km+FRA7s+5xB8e1UPcZqF4 UkorvyjoYOfmXOgNcwSKKWju8XXrfe39yTkB5nWGHYhliA9wc16JLTaHeigBjmnd lo2aD8pkjYDWn9uKhX0VkN8xQ+Fkiszz0I83TJ1TLESlT/1kgOeawrfcOlKMM+Ue GUhkTHys6Xv36jM00Wuakduh784+YIVeRwVqbQaBjpdzA+ffpMHLlevGuU5UJ2t5 1TKzYUeyfFF/gXsjC/lC3c67tpiGzQLMAbTkjP325uLQ==
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=qBhlh02LERehkSuLwVQsD1xp3NKY8ekZWjOdYAGQ9 NE=; b=opqg0JM4MIA+UbEsrkrzzpL1gzeuW8Qln1D23CYhqYKSt0bDECWx340LL ck3NS6ELZkVQgr8aAsAk8kaTpT7rzRdAtFd4woI3VATvPX6ikzoYpQXZjLWlvgt2 QhjE6SjSgxyyFir3u06RuxGvWptpRGSPrlfeo63dtMJBSzjBNM6jqPuFOgo/El3E NWgPJMFjTPD/T8P9d/BESjBrDZBTKc+83KpIVbEGYNMWTF1DxajdChaBKpn+SqTn O6n1dwmwHWx1aM+ixR9C0m+W6vJoxU63JLpqthAe24AGj7PbQie6q5K1DdYOX13E 5nEGBlQ9q7e5QUBZ7QcFULMwHrDsQ==
- In-reply-to: <441849700.1433895.1598439442873@mail2.virginmedia.com>
- List-archive: <http://www.zsh.org/sympa/arc/zsh-users>
- List-help: <mailto:sympa@zsh.org?subject=help>
- List-id: <zsh-users.zsh.org>
- List-owner: <mailto:zsh-users-request@zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-subscribe: <mailto:sympa@zsh.org?subject=subscribe%20zsh-users>
- List-unsubscribe: <mailto:sympa@zsh.org?subject=unsubscribe%20zsh-users>
- References: <CAHAhJwJdcSYaftAkfOyv2v63LW-SdwV+34LZh0i-E3GUJzZv1g@mail.gmail.com> <441849700.1433895.1598439442873@mail2.virginmedia.com>
- Sender: zsh-users-request@xxxxxxx
Elaborating per the request in users/26049.
Peter Stephenson wrote on Wed, 26 Aug 2020 11:57 +0100:
> > Please help me understand how to use tags in zsh completion system.
>
> Just off the top of my head (other people may have their own favourite
> examples), one interesting command with a number of different tags
> that apply at the start of completion is scp: ^xh for that gives me
>
> tags in context :completion::complete:scp::
> argument-rest options (_arguments _ssh _ssh)
> tags in context :completion::complete:scp:argument-rest:
> files hosts users (_ssh _ssh)
> globbed-files (_files _ssh _ssh)
> hosts (_hosts _combination _ssh_hosts _ssh _ssh)
> users (_users _combination _ssh_users _ssh _ssh)
>
> so that might be something to play with.
The scp(1) command can be invoked in several different ways:
.
scp $localfile ${remotehost}:
scp $remoteuser@$remotehost: $localfile
scp ${remotehost}: $localfile
.
Thus, «scp <TAB>» completes three kinds of things: local files,
usernames for remote login, and hostnames for remote login.
The completion system knows what type of thing each possible
completion is. Each tag — in this example, "files", "hosts",
"users", and "globbed-files" — corresponds to a single "type of thing"
that can be completed at that point. (I'm not sure how "globbed-files"
gets there, but you needn't worry about that right now.)
You can see completions grouped by tag by setting the group-name style:
$ zsh -f
% autoload compinit
% compinit
% zstyle :completion:\* group-name ''
% zstyle :completion:\*:descriptions format '→ %d'
% scp <TAB>
→ file
bar.txt foo.txt
→ remote host name
hermes.example.org localhost
→ user
danielsh root
You can reorder the three groups of candidate completions by setting the
tag-order style appropriately. For example, «zstyle \* tag-order users
hosts files» will show the groups in a different order than above.
Tag names are also part of the zstyle context string (the thing context
patterns are matched against), so styles can be set for some tags but
not others. For example, «zstyle ':completion:*:options' prefix-hidden true»
will set the prefix-hidden style whilst listing candidate completions
that are options, but not whilst listing other candidate completions.
As Peter said elsethread, you can generally forget about tags unless
you're either configuring completion system or writing your own
completion function (which you wouldn't generally need to do, unless
you wrote a custom command as well).
Cheers,
Daniel
Messages sorted by:
Reverse Date,
Date,
Thread,
Author