zstyle: changing the description style value of a tag

194 Views Asked by At

I use the following zstyle commands to group completion items by their description:

zstyle ':completion:*:*:*:*:descriptions' format '%F{green}-- %d --%f'
zstyle ':completion:*' group-name ''

zstyle ':completion:*:ssh:*:users' users alice bob eve
zstyle ':completion:*:ssh:*:hosts' hosts lenovo hp asus

Which, for the ssh command, display something like this:

$ ssh <TAB>
-- remote host name --
asus    hp      lenovo
-- login name --
alice   bob     eve

My question: how can I change the descriptions for the tags users and hosts? That is, to replace "remote host name" by something like "hosts" and "login name" by "users".

I have tried the following, but it has no effect:

zstyle ':completion:*:ssh:*:hosts' group-name 'hosts'
zstyle ':completion:*:ssh:*:hosts' description 'hosts'
1

There are 1 best solutions below

1
Martin von Wittich On BEST ANSWER

I'm still trying to grok zstyle myself, so take what I'm saying with a bit of salt.

First of all, this seems to work, but I don't think it's quite correct:

zstyle ':completion:*:ssh:*:users' users alice bob eve
zstyle ':completion:*:ssh:*:hosts' hosts lenovo hp asus

zstyle itself has helpful completion which you can use to figure out which field has which purpose. This is telling me:


host ~ # zstyle ':completion:
completion widget
all-matches        complete-tag       expand-alias-word  history-words
complete-debug     correct-word       expand-word

host ~ # zstyle ':completion:*:
completer
approximate  correct      history      list         menu         prefix
complete     expand       ignored      match        oldlist

host ~ # zstyle ':completion:*:*:
external command
[                                              klockstat-bpfcc
7z                                             kmod
7za                                            lap
[...]

host ~ # zstyle ':completion:*:*:ssh:
argument

host ~ # zstyle ':completion:*:*:ssh:*:
tag
accounts           devices            interfaces         nicknames          sessions
all-expansions     directories        jobs               options            signals
all-files          directory-stack    keymaps            original           strings
[...]

host ~ # zstyle ':completion:*:*:ssh:*:users'                                         
style
accept-exact              filter                    max-exports               sort
accept-exact-dirs         force-list                max-matches-width         special-dirs
[...]

So with zstyle ':completion:*:ssh:*:users', you're accidentally giving ssh as completer, * as external command and hosts as argument. I can't quite figure out why it works nonetheless, but I believe this would be more correct, and still works for me:

zstyle ':completion:*:*:ssh:*:users' users alice bob eve
zstyle ':completion:*:*:ssh:*:hosts' hosts lenovo hp asus

Further on, I don't think that these two do what you expect:

zstyle ':completion:*:ssh:*:hosts' group-name 'hosts'
zstyle ':completion:*:ssh:*:hosts' description 'hosts'

From what I can tell from man zshcompsys, group-name is used to group or ungroup several different tags (ie. if you wanted to configure whether users and hosts should be grouped together or not). description isn't completed by zstyle and isn't documented in the manpage, so I guess you've made that up :)

What I think you actually want, is, funnily enough... format, which you've already set here globally:

zstyle ':completion:*:*:*:*:descriptions' format '%F{green}-- %d --%f'

The %d is replaced with the descriptions given by the tags. So to get your custom descriptions, simply set different formats for your users/hosts tags, and replace %d with the description you want:

zstyle ':completion:*:*:ssh:*:users' format '%F{green}-- users --%f'
zstyle ':completion:*:*:ssh:*:hosts' format '%F{green}-- hosts --%f'

This works for me:

host ~ # ssh
-- hosts --
asus    hp      lenovo
-- users --
alice   bob     eve