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

PATCH: completing stuff from NIS



In _groups, if it finds ypcat, it only completes those groups found by
NIS. The list should really be merged with those from /etc/group
because the conventional setup involves using both.

On at least recent Solaris and Linux, the getent programme does a
better job of getting the groups. It should in theory work for ldap
setups too. For this reason, I've got it to try getent first. Hopefully
that doesn't cause problems on other systems. The only difference I
notice is that it isn't returning the ipv6 hosts. Whether that's a
limitation or a feature I don't know (I don't have ipv6 enabled but
/etc/hosts contains the ipv6 loopback things).

If we're going to pull groups from NIS, it can't do any harm to do a
similar thing for _hosts and _printers. I also add that in the patch
below. The printer part only works for Solaris.

Long ago, someone posted a patch to use a DNS search in _hosts. Any
thoughts on how we can reasonably add that. Perhaps a style to enable
it? Or we could do something like _email_addresses.

Oliver

Index: Completion/Unix/Type/_groups
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_groups,v
retrieving revision 1.2
diff -u -r1.2 _groups
--- Completion/Unix/Type/_groups	6 Aug 2001 14:42:04 -0000	1.2
+++ Completion/Unix/Type/_groups	18 Feb 2004 11:46:18 -0000
@@ -6,11 +6,14 @@
 
 if ! zstyle -a ":completion:${curcontext}:" groups groups; then
   (( $+_cache_groups )) ||
-      if (( ${+commands[ypcat]} )) &&
-	  tmp=$(_call_program groups ypcat group.byname 2>/dev/null); then
-        : ${(A)_cache_groups:=${${(f)tmp}%%:*}} # If you use YP
+      if (( ${+commands[getent]} )); then
+        : ${(A)_cache_groups:=${${(s: :)$(_call_program groups getent group 2>/dev/null)}%%:*}}
       else
-        : ${(A)_cache_groups:=${${(s: :)$(</etc/group)}%%:*}}
+        : ${(A)_cache_groups:=${${${(s: :)$(</etc/group)}%%:*}:#+}}
+	if (( ${+commands[ypcat]} )) &&
+	    tmp=$(_call_program groups ypcat group.byname 2>/dev/null); then
+          _cache_groups+=( ${${(f)tmp}%%:*} ) # If you use YP
+	fi
       fi
 
   groups=( "$_cache_groups[@]" )
Index: Completion/Unix/Type/_hosts
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_hosts,v
retrieving revision 1.2
diff -u -r1.2 _hosts
--- Completion/Unix/Type/_hosts	12 Apr 2002 23:22:57 -0000	1.2
+++ Completion/Unix/Type/_hosts	18 Feb 2004 11:46:18 -0000
@@ -1,10 +1,18 @@
 #compdef ftp ping rwho rup xping traceroute host aaaa zone mx ns soa txt
 
-local expl hosts
+local expl hosts tmp
 
 if ! zstyle -a ":completion:${curcontext}:hosts" hosts hosts; then
   (( $+_cache_hosts )) ||
-      : ${(A)_cache_hosts:=${(s: :)${(ps:\t:)${${(f)~~"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}}
+      if (( ${+commands[getent]} )); then
+	: ${(A)_cache_hosts:=${(s: :)${(ps:\t:)${(f)~~"$(_call_program hosts getent hosts 2>/dev/null)"}##[:blank:]#[^[:blank:]]#}}}
+      else
+        : ${(A)_cache_hosts:=${(s: :)${(ps:\t:)${${(f)~~"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}}
+	if (( ${+commands[ypcat]} )) &&
+	    tmp=$(_call_program hosts ypcat hosts.byname 2>/dev/null); then
+          _cache_hosts+=( ${=${(f)tmp}##[:blank:]#[^[:blank:]]#} ) # If you use YP
+	fi
+      fi
 
   hosts=( "$_cache_hosts[@]" )
 fi
Index: Completion/Unix/Type/_printers
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_printers,v
retrieving revision 1.4
diff -u -r1.4 _printers
--- Completion/Unix/Type/_printers	13 Mar 2002 09:28:05 -0000	1.4
+++ Completion/Unix/Type/_printers	18 Feb 2004 11:46:18 -0000
@@ -1,6 +1,6 @@
 #compdef -value-,PRINTER,-default- -value-,LPDEST,-default-
 
-local expl ret=1 list disp sep
+local expl ret=1 list disp sep tmp
 
 if (( $+commands[lsallq] )); then
   # Use AIX's command to list print queues
@@ -39,6 +39,12 @@
       fi
     done < $file[1]
   fi
+
+  if [[ $OSTYPE = solaris* ]] && (( ${+commands[ypcat]} )) &&
+      tmp=$(_call_program printers ypcat printers.conf.byname 2>/dev/null); then
+    _lp_cache+=( ${${${(S)${(f)tmp}/(#b):*((#e)|description=([^:]#):)*/:${match[2]}|}%%|*}:#_default*} ) # If you use YP
+  fi
+
   (( $#_lp_cache )) || _lp_cache=( 'lp0:Guessed default printer' )
   (( $#_lp_alias_cache )) || unset _lp_alias_cache
 fi



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