about summary refs log tree commit diff
path: root/Completion/Unix/Command/_chown
diff options
context:
space:
mode:
authorOliver Kiddle <opk@users.sourceforge.net>2003-08-20 09:03:05 +0000
committerOliver Kiddle <opk@users.sourceforge.net>2003-08-20 09:03:05 +0000
commit6d8b974765b25542495af0459c6f2832096741c5 (patch)
treedbec3d29c3bc8a51920580663e093870652d1b56 /Completion/Unix/Command/_chown
parent5dfa9ad36a75964ea10679f64f36a1b4e7e351d1 (diff)
downloadzsh-6d8b974765b25542495af0459c6f2832096741c5.tar.gz
zsh-6d8b974765b25542495af0459c6f2832096741c5.tar.xz
zsh-6d8b974765b25542495af0459c6f2832096741c5.zip
18947: also complete options using _arguments
Diffstat (limited to 'Completion/Unix/Command/_chown')
-rw-r--r--Completion/Unix/Command/_chown105
1 files changed, 73 insertions, 32 deletions
diff --git a/Completion/Unix/Command/_chown b/Completion/Unix/Command/_chown
index e194677d2..26dec1159 100644
--- a/Completion/Unix/Command/_chown
+++ b/Completion/Unix/Command/_chown
@@ -1,41 +1,82 @@
 #compdef chown chgrp
 
-local suf usr grp req line
+local curcontext="$curcontext" state line expl ret=1
+local suf usr grp req deref args
 
-line=( "${(@)words[2,CURRENT-1]:#-*}" )
+if _pick_variant gnu=Free\ Soft unix --version; then
+  args=(
+    '(-c --changes -v --verbose)'{-c,--changes}'[report each change made]'
+    '(-c --changes -v --verbose)'{-v,--verbose}'[output info for every file processed]'
+    '(-h --no-dereference)--dereference[dereference symlinks]'
+    '(-h --no-dereference --dereference)'{-h,--no-dereference}'[operate on symlinks them self]'
+    '(-f --silent --quiet)'{-f,--silent,--quiet}"[don't report errors]"
+    '--reference=[copy ownership of specified file]:file:_files'
+    '(-R --recursive)'{-R,--recursive}'[change files and directories recursively]'
+    '(- : *)--help[display help information]'
+    '(- : *)--version[display version information]'
+  )    
+  [[ $service = chown ]] &&
+      args+=( '--from=[restrict changes to files by current ownership]: :->owner' )
+else
+  # based on $OSTYPE = solaris2.8
+  args=(
+    "-f[don't report errors]"
+    "-h[operate on symlinks them self]"
+    '-R[change files and directories recursively]'
+  )
+fi
 
-if [[ -prefix - ]]; then
-  _message -e options option
-elif [[ $#line -eq 0 ]]; then
-  if [[ $service = chgrp ]] || compset -P '*[:.]'; then
-    if (( EGID && $+commands[groups] )); then  # except for root
-      _wanted groups expl 'group' compadd $(groups) && return 0
+(( $+words[(r)--reference*] )) || args+=( '(--reference)1: :->owner' )
+_arguments -C -s "$args[@]" '*:files:->files' && ret=0
+
+case $state in
+  owner)
+    if [[ $service = chgrp ]] || compset -P '*[:.]'; then
+      if (( EGID && $+commands[groups] )); then  # except for root
+	_wanted groups expl 'group' compadd $(groups) && return 0
+      fi
+      _groups && ret=0
+    else
+      if compset -S '[.:]*'; then
+        suf=()
+      elif [[ $OSTYPE = (solaris*|hpux*|*bsd*) ]]; then
+	suf=( -qS ':' )
+      else
+	suf=( -qS '.' )
+      fi
+      _users "$suf[@]" && ret=0
     fi
-    _groups && return 0
-  else
-    if [[ $OSTYPE = (solaris*|hpux*|*bsd*) ]]; then
-      suf=':'
+  ;;
+  files)
+    (( $+opt_args[-h] || $+opt_args[--no-dereference] )) || deref="-"
+    if (( $+opt_args[--reference] )); then
+      if zstyle -t ":completion:${curcontext}:" disable-stat; then
+	_files && ret=0
+      else
+	zmodload -i zsh/stat 2>/dev/null
+	usr=$(stat +uid $opt_args[--reference])
+	grp=$(stat +gid $opt_args[--reference])
+	_wanted files expl file _files -g "*($deref^u$usr,$deref^g$grp)" && ret=0
+      fi
+      return ret
+    fi
+    if [[ $service = chgrp ]]; then
+      grp=${line[1]}
     else
-      suf='.'
+      usr=${line[1]%%[.:]*}
+      usr=${${(M)usr:#[0-9]#}:-${userdirs[$usr]:+.$usr.}}
+      grp=${${(M)line[1]%%[.:]*}#?}
     fi
-    compset -S '.*' && unset suf
-    _users -S "$suf" -q && return 0
-  fi
-else
-  if [[ $service = chgrp ]]; then
-    grp=${line[1]}
-  else
-    usr=${line[1]%%[.:]*}
-    usr=${${(M)usr:#[0-9]#}:-${userdirs[$usr]:+.$usr.}}
-    grp=${${(M)line[1]%%[.:]*}#?}
-  fi
-  [[ -n $grp ]] && grp="${${(M)grp:#[0-9]#}:-.$grp.}"
-  req=( ${usr:+\^u$usr} ${grp:+\^g$grp} )
-  (( EUID )) && req=( u$EUID$^req )
-  req=( -$^req )
-  req="*(${(j:,:)req})"
+    [[ -n $grp ]] && grp="${${(M)grp:#[0-9]#}:-.$grp.}"
+    req=( ${usr:+\^u$usr} ${grp:+\^g$grp} )
+    (( EUID )) && req=( u$EUID$^req )
+    req=( $deref$^req )
+    req="*(${(j:,:)req})"
 
-  ( : $~req ) 2> /dev/null || req='*'
+    ( : $~req ) 2> /dev/null || req='*'
 
-  _files -g "$req" && return 0
-fi
+    _wanted files expl file _files -g "$req" && ret=0
+  ;;
+esac
+
+return ret