about summary refs log tree commit diff
path: root/Completion/Unix
diff options
context:
space:
mode:
authorOliver Kiddle <opk@users.sourceforge.net>2001-05-09 15:27:01 +0000
committerOliver Kiddle <opk@users.sourceforge.net>2001-05-09 15:27:01 +0000
commit7f4eb970858cfd8f2a1e4dd716c403623a23a066 (patch)
tree0373fca7e37df653b938b6def67d0ca9dec70936 /Completion/Unix
parente364fb2139df94df3c4aac406e56b133d3e497b1 (diff)
downloadzsh-7f4eb970858cfd8f2a1e4dd716c403623a23a066.tar.gz
zsh-7f4eb970858cfd8f2a1e4dd716c403623a23a066.tar.xz
zsh-7f4eb970858cfd8f2a1e4dd716c403623a23a066.zip
complete only files that can be chowned (14282)
Diffstat (limited to 'Completion/Unix')
-rw-r--r--Completion/Unix/Command/_chown22
1 files changed, 18 insertions, 4 deletions
diff --git a/Completion/Unix/Command/_chown b/Completion/Unix/Command/_chown
index 40f38d2f4..83fcb3056 100644
--- a/Completion/Unix/Command/_chown
+++ b/Completion/Unix/Command/_chown
@@ -1,10 +1,13 @@
 #compdef chown chgrp
 
-local suf
+local suf usr grp req expl
 
 if [[ CURRENT -eq 2 || CURRENT -eq 3 && $words[CURRENT-1] = -* ]]; then
   if [[ $service = chgrp ]] || compset -P '*[:.]'; then
-    _groups
+    if (( EGID && $+commands[groups] )); then  # except for root
+      _wanted groups expl 'group' compadd $(groups) && return 0
+    fi
+    _groups && return 0
   else
     if [[ $OSTYPE = (solaris*|hpux*) ]]; then
       suf=':'
@@ -12,8 +15,19 @@ if [[ CURRENT -eq 2 || CURRENT -eq 3 && $words[CURRENT-1] = -* ]]; then
       suf='.'
     fi
     compset -S '.*' && unset suf
-    _users -S "$suf" -q
+    _users -S "$suf" -q && return 0
   fi
 else
-  _files
+  if [[ $service = chgrp ]]; then
+    grp=${words[CURRENT-1]}
+  else
+    usr=${words[CURRENT-1]%%[.:]*}
+    usr=${${(M)usr:#[0-9]#}:-${userdirs[$usr]:+.$usr.}}
+    grp=${${(M)words[CURRENT-1]%%[.:]*}#?}
+  fi
+  [[ -n $grp ]] && grp="${${(M)grp:#[0-9]#}:-.$grp.}"
+  req=( ${usr:+\^u$usr} ${grp:+\^g$grp} )
+  (( EUID )) && req=( u$EUID$^req )
+
+  _files -g "*(${(j:,:)req})" && return 0
 fi