浏览代码

fix(ssh): allow multiple definitions per host (#12227)

Gam 2 月之前
父节点
当前提交
50fd98e5a6
共有 1 个文件被更改,包括 10 次插入3 次删除
  1. 10 3
      plugins/ssh/ssh.plugin.zsh

+ 10 - 3
plugins/ssh/ssh.plugin.zsh

@@ -4,9 +4,16 @@
 # Filter out wildcard host sections.
 _ssh_configfile="$HOME/.ssh/config"
 if [[ -f "$_ssh_configfile" ]]; then
-  _hosts=($(egrep '^Host.*' "$_ssh_configfile" | awk '{print $2}' | grep -v '^*' | sed -e 's/\.*\*$//'))
-  zstyle ':completion:*:hosts' hosts $_hosts
-  unset _hosts
+  _ssh_hosts=($(
+    egrep '^Host.*' "$_ssh_configfile" |\
+    awk '{for (i=2; i<=NF; i++) print $i}' |\
+    sort |\
+    uniq |\
+    grep -v '^*' |\
+    sed -e 's/\.*\*$//'
+  ))
+  zstyle ':completion:*:hosts' hosts $_ssh_hosts
+  unset _ssh_hosts
 fi
 unset _ssh_configfile