summary refs log tree commit diff
path: root/Completion
diff options
context:
space:
mode:
authorBarton E. Schaefer <schaefer@zsh.org>2017-05-28 11:27:55 -0700
committerBarton E. Schaefer <schaefer@zsh.org>2017-05-28 11:27:55 -0700
commit5ded0ad96740b62ea0214387ee260b515726a05e (patch)
tree920d086576f379b99e6038cf00d9e9aee1c2bbd4 /Completion
parent62c416915b1bee6d7ef9dc87f6009907748f2087 (diff)
downloadzsh-5ded0ad96740b62ea0214387ee260b515726a05e.tar.gz
zsh-5ded0ad96740b62ea0214387ee260b515726a05e.tar.xz
zsh-5ded0ad96740b62ea0214387ee260b515726a05e.zip
41159: handle "Include" and "HostName" lines in ~/.ssh/config
Added 2>/dev/null to conceal file access errors.
Diffstat (limited to 'Completion')
-rw-r--r--Completion/Unix/Command/_ssh28
1 files changed, 17 insertions, 11 deletions
diff --git a/Completion/Unix/Command/_ssh b/Completion/Unix/Command/_ssh
index 6763e24e7..28d2c38e7 100644
--- a/Completion/Unix/Command/_ssh
+++ b/Completion/Unix/Command/_ssh
@@ -680,17 +680,23 @@ _ssh_hosts () {
     config="$HOME/.ssh/config"
   fi
   if [[ -r $config ]]; then
-    local key hosts host
-    while IFS=$'=\t ' read -r key hosts; do
-      if [[ "$key" == (#i)host ]]; then
-         for host in ${(z)hosts}; do
-            case $host in
-            (*[*?]*) ;;
-            (*) config_hosts+=("$host") ;;
-            esac
-         done
-      fi
-    done < "$config"
+    local key line host
+    local -a lines=("${(@f)$(<"$config")}") 2>/dev/null
+    while (($#lines)); do
+      IFS=$'=\t ' read -r key line <<<"${lines[1]}"
+      case "$key" in
+      ((#i)include)
+        lines[1]=("${(@f)$(cd $HOME/.ssh; cat ${(z)~line})}") 2>/dev/null;;
+      ((#i)host(|name))
+        for host in ${(z)line}; do
+          case $host in
+          (*[*?]*) ;;
+          (*) config_hosts+=("$host") ;;
+          esac
+        done ;&
+      (*) shift lines;;
+      esac
+    done
     if (( ${#config_hosts} )); then
       _wanted hosts expl 'remote host name' \
         compadd -M 'm:{a-zA-Z}={A-Za-z} r:|.=* r:|=*' "$@" $config_hosts