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

Re: users-hosts combination failing

Chris Johnson wrote:
> Chris Johnson sent me the following 0.8K:
> > Hi.  I've got one machine running zsh 4.2.5 with following completion
> > styles defined:
> > 
> >    zstyle '*:my-accounts' users user1 user2
> >    zstyle '*:my-accounts' hosts machine1 machine2 machine3
> >    zstyle '*:my-accounts' users-hosts user3@machine4 user4@machine5
> > 
> > If I type user3 and hit tab, machine4 is completed.  However, on another
> > machine with the exact same configurtion and zsh 4.2.6, I get all
> > machine* offered as possible completions.  I know I should probably
> > update to a newer zsh, but is this problem known about and can anyone
> > offer a solution?
> Hmm...  No responses yet.  Is there anyway I can I provide more
> information?

I've finally caught up with the problem, and it's still present.

_ssh_hosts was altered so that it unconditionally searches the list of
hosts in the configuration file.  The documentation of the users-hosts
style is quite clear that it shouldn't if there was a match there:

     The values of this style should be of the form `USER@HOST' or
     `USER:HOST'. It is used for commands that need pairs of user- and
     hostnames.  These commands will complete usernames from this style
     (only), and will restrict subsequent hostname completion to hosts
     paired with that user in one of the values of the style.

So the behaviour is wrong.  This patch makes _ssh_hosts return if
users-hosts matches.

There may be cases where this gives less than optimum behaviour,
but I don't think so:  at this point we're only completing the host
part so we've already got the user name to test.

Index: Completion/Unix/Command/_ssh
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_ssh,v
retrieving revision 1.31
diff -u -r1.31 _ssh
--- Completion/Unix/Command/_ssh	14 Nov 2006 17:16:40 -0000	1.31
+++ Completion/Unix/Command/_ssh	25 Mar 2007 12:48:49 -0000
@@ -326,11 +326,12 @@
   local config
   integer ind
+  # If users-hosts matches, we shouldn't complete anything else.
   if [[ "$IPREFIX" == *@ ]]; then
-    _combination -s '[:@]' my-accounts users-hosts "users=${IPREFIX/@}" hosts "$@"
+    _combination -s '[:@]' my-accounts users-hosts "users=${IPREFIX/@}" hosts "$@" && return
     _combination -s '[:@]' my-accounts users-hosts \
-      ${opt_args[-l]:+"users=${opt_args[-l]:q}"} hosts "$@"
+      ${opt_args[-l]:+"users=${opt_args[-l]:q}"} hosts "$@" && return
   if (( ind = ${words[(I)-F]} )); then

Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/

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