1

When I attempt to autocomplete ssh in zsh, I am presented with two types of lists.

$ ssh a<TAB>
 -- remote host name --
aur
 -- login name --
avahi

However, the latter is not useful to me. Is it possible to suppress everything under -- login name --, leaving only entries under -- remote host name --?

I also get multiple entries when using rsync, although the headings differ.

$ rsync a<TAB>
 -- user --
avahi
 -- host --
aur

I'd like to suppress entries under -- user -- here.


Possibly pertinent information

I use zim. Also, the following is in ~/.zshrc.

h=()
if [[ -r ~/.ssh/config ]]; then
  h=($h ${${${(@M)${(f)"$(cat ~/.ssh/config)"}:#Host *}#Host }:#*[*?]*})
fi
if [[ $#h -gt 0 ]]; then
  zstyle ':completion:*:ssh:*' hosts $h
  zstyle ':completion:*:slogin:*' hosts $h
  zstyle ':completion:*:rsync:*' hosts $h
fi

This a workaround for a bug in zim where tab completion works with hostnames instead of hosts.

  • OT: there's zim, and then there's zim. :) I presume you mean the former. – Satō Katsura Apr 4 '17 at 11:32
2

You can use the users style:

zstyle ':completion:*' users

Setting an empty list like this disables completion on user names. You can narrow it down to individual commands, if you like:

zstyle ':completion:*:rsync:*' users

for example, would disable it for rsync but leave it on elsewhere.

The zsh completion system is very sophisticated, and its configuration complex. The zshcompsys man page covers the new style of completion, as demonstrated here, and the zstyle command is documented in the zshmodules man page.

  • Thanks, that works perfectly (+1)! Could you please put some information in about that command, and/or a link? Also, would it have been possible to deduct that the relevant style was called users, when (as per the question) it was presented under the headings of login name and user? Or is it just something you had to know prior? – Sparhawk Apr 4 '17 at 11:36
  • Added details of where you can find more documentation. I think you'd probably need a little prior knowledge to know which completer to use in this case. – D_Bye Apr 4 '17 at 11:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.