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

_groups change for Mac OS X version 10.5



Hi,
In Mac OS X version 10.5, the lookupd command has been replaced with dscacheutil, which requires a change to _groups in order for group completion to work properly.  Here's what Apple has done:

--- zsh-4.3.4/Completion/Unix/Type/_groups 2005-06-08 07:45:35.000000000 -0500
+++ /usr/share/zsh/4.3.4/functions/_groups 2007-09-23 20:40:47.000000000 -0500
@@ -7,7 +7,7 @@
if ! zstyle -a ":completion:${curcontext}:" groups groups; then
 (( $+_cache_groups )) ||
     if [[ $OSTYPE = darwin* ]]; then
-        : ${(A)_cache_groups:=${${(M)${(f)"$(_call_program groups lookupd -q group)"}:#name*}##*: }}
+        : ${(A)_cache_groups:=${${(M)${(f)"$(_call_program groups dscacheutil -q group)"}:#name*}##*: }}
     elif (( ${+commands[getent]} )); then
       : ${(A)_cache_groups:=${${(s: :)$(_call_program groups getent group 2>/dev/null)}%%:*}}
     else

However, this change would break pre-10.5 systems which have lookupd and not dscacheutil.  I propose something like this:

--- zsh-4.3.4/Completion/Unix/Type/_groups.orig 2007-10-28 16:41:48.000000000 -0500
+++ zsh-4.3.4/Completion/Unix/Type/_groups 2007-10-28 16:42:55.000000000 -0500
@@ -7,7 +7,11 @@
if ! zstyle -a ":completion:${curcontext}:" groups groups; then
 (( $+_cache_groups )) ||
     if [[ $OSTYPE = darwin* ]]; then
-        : ${(A)_cache_groups:=${${(M)${(f)"$(_call_program groups lookupd -q group)"}:#name*}##*: }}
+        if (( ${+commands[lookupd]} )); then
+          : ${(A)_cache_groups:=${${(M)${(f)"$(_call_program groups lookupd -q group)"}:#name*}##*: }}
+        elif (( ${+commands[dscacheutil]} )); then
+          : ${(A)_cache_groups:=${${(M)${(f)"$(_call_program groups dscacheutil -q group)"}:#name*}##*: }}
+        fi
     elif (( ${+commands[getent]} )); then
       : ${(A)_cache_groups:=${${(s: :)$(_call_program groups getent group 2>/dev/null)}%%:*}}
     else

I suppose one could even get rid of the 'if [[ $OSTYPE == darwin* ]]; then...fi' part but that may not be as safe if non-OS X systems ever implement lookupd and/or dscacheutil commands which behave differently from the same commands on OS X.


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