Ssh

zsh ssh 自動完成主機而不是來自 ~/.ssh/hosts 的主機名

  • November 18, 2019

有沒有辦法讓我~/.zshrc的 ssh 自動完成自動完成Host,而不是Hostname

我的條目~/.ssh/config如下所示:

Host staging-rfc staging
 User crmpicco
 Hostname staging.rfc.crmpicco.co.uk

如果我輸入ssh sta[TAB],那麼它會預先填充完整的主機名staging.rfc.crmpicco.co.uk,這給了我一個權限被拒絕的錯誤——大概是因為它試圖用我的終端使用者而不是“crmpicco”登錄。

rfcpicco1872@staging.rfc.crmpicco.co.uk: Permission denied (publickey).

我的~/.zshrc

# Highlight the current autocomplete option
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"

# Better SSH/Rsync/SCP Autocomplete
zstyle ':completion:*:(scp|rsync):*' tag-order ' hosts:-ipaddr:ip\ address hosts:-host:host files'
zstyle ':completion:*:(ssh|scp|rsync):*:hosts-host' ignored-patterns '*(.|:)*' loopback ip6-loopback localhost ip6-localhost broadcasthost
zstyle ':completion:*:(ssh|scp|rsync):*:hosts-ipaddr' ignored-patterns '^(<->.<->.<->.<->|(|::)([[:xdigit:].]##:(#c,2))##(|%*))' '127.0.0.<->' '255.255.255.255' '::1' 'fe80::*'

# Allow for autocomplete to be case insensitive
zstyle ':completion:*' matcher-list '' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' \
 '+l:|?=** r:|?=**'

# Initialize the autocompletion
autoload -Uz compinit && compinit -i

將 my 更改zstyle為以下內容非常有效:

zstyle ':completion:*:(ssh|scp|ftp|sftp):*' hosts $hosts
zstyle ':completion:*:(ssh|scp|ftp|sftp):*' users $users

引用自:https://unix.stackexchange.com/questions/551894