首页 > 解决方案 > zsh completion: Disable ssh username completion

问题描述

I am using the completion scripts that ship with ZSH (5.7.1) and I would like to turn off the autocompletion for usernames, but keep the completion for hostnames.

How can I do this?

Currently, there's an erroneous user that I can't figure out why it's being included (not in ~/.ssh/config, any identities, /etc/ssh, or any other location) and I figure it's probably easier to just disable username completion.

Example output is below; I want to remove the entire "login name" section rather than try and hunt down where unwanted-username is coming from.

$ ssh <tab>
 -- login name --
unwanted-username
 -- host --
example-host-1      example-host-1

I expect there is a zstyle command which can disable it, but I'm not sure the correct incantation. I expect this is the relevant configuration that needs to be changed:

$ zstyle | grep completion | grep ssh
        :completion:*:ssh:* users hosts-domain hosts-host users hosts-ipaddr

However, I can't seem to get the correct incantation to remove the login name section.

标签: sshautocompletezsh

解决方案


要禁用登录名的完成,在这种情况下,请尝试:

zstyle ':completion:*:ssh:argument-1:*' tag-order hosts

或仅仅隐藏它们,请尝试:

zstyle ':completion:*:ssh:*:users' hidden true

Ctrl-X h而不是tab确定相关标签和上下文字符串的好方法。

您有一个错误的用户正在完成,这似乎很奇怪。检查正在设置的样式,可能没有在上下文中users-hosts提及。sshignored-patterns一般情况下,样式可能是另一种处理错误匹配的方法,例如:

zstyle ':completion:*:ssh:*:users' ignored-patterns erroneous-username

正如您可能从样式名称中看出的那样,这里的最后一个参数可以是带有 等的 shell*模式?


推荐阅读