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

Re: Mysterious completion of variables



On Fri, Nov 18, 2005 at 11:47:05AM +0000, Peter Stephenson wrote:
> +      if [[ "$key" == (#i)host ]]; then
> +         config_hosts+=("$host")
> +      fi

There's two problems with this for general use (as pointed out by Ian
himself):  it puts multiple hostnames into a single completion item, and
it includes wild-carded items as hostnames.  I patched the function like
this:

--- Completion/Unix/Command/_ssh	18 Nov 2005 14:53:44 -0000	1.25
+++ Completion/Unix/Command/_ssh	18 Nov 2005 17:22:39 -0000
@@ -320,10 +320,15 @@ _ssh_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
+    local IFS=$'\t ' key hosts host
+    while read key hosts; do
       if [[ "$key" == (#i)host ]]; then
-	 config_hosts+=("$host")
+	 for host in ${(z)hosts}; do
+	    case $host in
+	    (*[*?]*) ;;
+	    (*) config_hosts+=("$host") ;;
+	    esac
+	 done
       fi
     done < "$HOME/.ssh/config"
     if (( ${#config_hosts} )); then

There may well be a non-looping way to do that, so feel free to
enlighten me if there is.

..wayne..



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