summary refs log tree commit diff
path: root/Completion
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2005-11-18 14:53:43 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2005-11-18 14:53:43 +0000
commitb1c72569b9c44a3500ef512e53efdd6ac030b9f6 (patch)
treefb0f6620f7171499c35a616ac0bc41d00fbddc45 /Completion
parentfe3b0d58494b858c45ad149b54d0476046b29493 (diff)
downloadzsh-b1c72569b9c44a3500ef512e53efdd6ac030b9f6.tar.gz
zsh-b1c72569b9c44a3500ef512e53efdd6ac030b9f6.tar.xz
zsh-b1c72569b9c44a3500ef512e53efdd6ac030b9f6.zip
users/9688: improved _ssh_hosts from Hanna Koivisto
Diffstat (limited to 'Completion')
-rw-r--r--Completion/Unix/Command/_ssh20
1 files changed, 17 insertions, 3 deletions
diff --git a/Completion/Unix/Command/_ssh b/Completion/Unix/Command/_ssh
index b4b739019..0f2cb1dd5 100644
--- a/Completion/Unix/Command/_ssh
+++ b/Completion/Unix/Command/_ssh
@@ -283,11 +283,11 @@ _ssh () {
       elif compset -P '*@'; then
         suf=( -S '' )
         compset -S ':*' || suf=( -S : )
-        _wanted hosts expl host _ssh_hosts $suf && ret=0
+        _wanted hosts expl 'remote host name' _ssh_hosts $suf && ret=0
       else
         _alternative \
 	    'files:: _files' \
-	    'hosts:host:_ssh_hosts -S:' \
+	    'hosts:remote host name:_ssh_hosts -S:' \
 	    'users:user:_ssh_users -qS@' && ret=0
       fi
       ;;
@@ -298,7 +298,7 @@ _ssh () {
         _wanted hosts expl host _ssh_hosts -S: && ret=0
       else
         _alternative \
-	    'hosts:host:_ssh_hosts -S:' \
+	    'hosts:remote host name:_ssh_hosts -S:' \
 	    'users:user:_ssh_users -qS@' && ret=0
       fi
       ;;
@@ -311,12 +311,26 @@ _ssh_users () {
 }
 
 _ssh_hosts () {
+  local -a config_hosts
+
   if [[ "$IPREFIX" == *@ ]]; then
     _combination -s '[:@]' my-accounts users-hosts "users=${IPREFIX/@}" hosts "$@"
   else
     _combination -s '[:@]' my-accounts users-hosts \
       ${opt_args[-l]:+"users=${opt_args[-l]:q}"} hosts "$@"
   fi
+  if [[ -r "$HOME/.ssh/config" ]]; then
+    local IFS=$'\t ' key host
+    while read key host; do
+      if [[ "$key" == (#i)host ]]; then
+	 config_hosts+=("$host")
+      fi
+    done < "$HOME/.ssh/config"
+    if (( ${#config_hosts} )); then
+      _wanted hosts expl 'remote host name' \
+	compadd -M 'm:{a-zA-Z}={A-Za-z} r:|.=* r:|=*' "$@" $config_hosts
+    fi
+  fi
 }
 
 _ssh "$@"