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

Re: PATCH: _hosts



Danek Duvall wrote:
> Might want to strip out IPv6 addresses as well:
> 
>   -e '/^[0-9a-f]\{0,4\}:/d'
> 
> And I'm not sure I see what the "/p" is doing there, other than doubling
> each entry.  Would
> 
>     ${${${(u)${(f)"$(<~/.ssh/known_hosts)"}%%[ ,]*}:#(#s)[0-9]##.[0-9]##.[0-9
> ]##.[0-9]##(#e)}:#(#s)[0-9a-f:]##(#e)}
> 
> be any better (if more arcane)?

It matches the rest of the completion system...

The /p was because I started with perl -ne before I decided that sed was
more portable.

> _users calls
> 
>     zstyle -a ":completion:${curcontext}:" users users
> 
> compared to _hosts, which calls
> 
>     zstyle -a ":completion:${curcontext}:hosts" hosts hosts
> 
> Is there some reason that _hosts uses the hosts tag, but _users doesn't use
> the users tag?

I think it must be an oversight, given that the manual specifically
mentions the existence of a users tag (as well as a users style).

I agree it's also inconsistent that you can't skip the userdirs
completion.  There could probably be better caching of user names if
default completion is used (and, really, _hosts ought to use the cache
system, though the disadvantage is it has to be explicitly enabled).

I'll commit the following...

Index: Completion/Unix/Type/_hosts
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_hosts,v
retrieving revision 1.6
diff -u -r1.6 _hosts
--- Completion/Unix/Type/_hosts	3 Feb 2006 16:32:15 -0000	1.6
+++ Completion/Unix/Type/_hosts	3 Feb 2006 22:34:33 -0000
@@ -23,7 +23,7 @@
     fi
 
     if [[ -r ~/.ssh/known_hosts ]]; then
-      _cache_hosts+=( $(sed -e '/^[0-9]*\.[0-9]*\.[0-9]*\.[0-9]/d' -e 's/[ ,].*//p' ~/.ssh/known_hosts) )
+      _cache_hosts+=(${${${(u)${(f)"$(<~/.ssh/known_hosts)"}%%[ ,]*}:#(#s)[0-9]##.[0-9]##.[0-9]##.[0-9]##(#e)}:#(#s)[0-9a-f:]##(#e)})
     fi
   fi
 
Index: Completion/Unix/Type/_users
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_users,v
retrieving revision 1.5
diff -u -r1.5 _users
--- Completion/Unix/Type/_users	8 Jun 2005 12:45:36 -0000	1.5
+++ Completion/Unix/Type/_users	3 Feb 2006 22:34:33 -0000
@@ -2,7 +2,9 @@
 
 local expl users
 
-zstyle -a ":completion:${curcontext}:" users users &&
-    _wanted users expl user compadd "$@" -a - users && return 0
+if zstyle -a ":completion:${curcontext}:users" users users; then
+    _wanted users expl user compadd "$@" -a - users
+    return 0
+fi
 
 _wanted users expl user compadd "$@" -k - userdirs

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page still at http://www.pwstephenson.fsnet.co.uk/



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