Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Mysterious completion of variables



Hannu Koivisto <azure@xxxxxx> wrote:
> I modified ssh completion to dig host aliases from the
> configuration file.

I'll commit it in the following form.

The only point of changing "host" to "remote host name" everywhere is that
otherwise the hosts appear under two separate names (if you have the
descriptions turned on).  I'm not attached to the latter rather than the
form, it just has to be consistent throughout.

I'm not sure whether the extra _wanted in _ssh_hosts is needed, given how
_ssh_hosts is called, but I think it's at least harmless.

Index: Completion/Unix/Command/_ssh
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_ssh,v
retrieving revision 1.24
diff -u -r1.24 _ssh
--- Completion/Unix/Command/_ssh	9 May 2005 02:38:35 -0000	1.24
+++ Completion/Unix/Command/_ssh	18 Nov 2005 11:44:47 -0000
@@ -283,11 +283,11 @@
       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 @@
         _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_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 "$@"


This message has been scanned for viruses by BlackSpider MailControl - www.blackspider.com



Messages sorted by: Reverse Date, Date, Thread, Author