aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOliver Kiddle <opk@users.sourceforge.net>2003-08-20 09:23:40 +0000
committerOliver Kiddle <opk@users.sourceforge.net>2003-08-20 09:23:40 +0000
commite438f826e34d2365a1aaf1cefdea2ac15b589129 (patch)
tree210ce5ab5bcdd57bc9bfe57a99a14f50991cda47
parent564504c1d641af1629737beb9456f59636375fe9 (diff)
downloadzsh-e438f826e34d2365a1aaf1cefdea2ac15b589129.tar.gz
zsh-e438f826e34d2365a1aaf1cefdea2ac15b589129.tar.xz
zsh-e438f826e34d2365a1aaf1cefdea2ac15b589129.zip
18947: also complete options using _arguments
-rw-r--r--ChangeLog6
-rw-r--r--Completion/Unix/Command/_chown104
2 files changed, 80 insertions, 30 deletions
diff --git a/ChangeLog b/ChangeLog
index 55d2acc0f..2b296e8c6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2003-08-20 Oliver Kiddle <opk@zsh.org>
+
+ * 18947: Completion/Unix/Command/_chown: also complete options using
+ _arguments
+
2003-08-05 Peter Stephenson <pws@csr.com>
* 18926: Src/Zle/complist.c: fix (without knowing how) insertion
@@ -257,6 +262,7 @@
* 18346: Completion/Unix/Type/_pids, Completion/Unix/Type/_users:
complete for more commands using existing completions
+
2003-03-12 Doug Kearns <djkea2@mugca.its.monash.edu.au>
* unposted: Completion/Debian/Command/_debfoster,
diff --git a/Completion/Unix/Command/_chown b/Completion/Unix/Command/_chown
index 2e55209c5..3b2372319 100644
--- a/Completion/Unix/Command/_chown
+++ b/Completion/Unix/Command/_chown
@@ -1,38 +1,82 @@
#compdef chown chgrp
-local suf usr grp req expl line
+local curcontext="$curcontext" state line expl ret=1
+local suf usr grp req deref args
-line=( "${(@)words[2,CURRENT-1]:#-*}" )
+if [[ $(_call_program version $words[1] --version 2>&1) = *Free\ Soft* ]]; 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=( $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
+
+(( $+words[(r)--reference*] )) || args=( $args '(--reference)1: :->owner' )
+_arguments -C -s "$args[@]" '*:files:->files' && ret=0
-if [[ -prefix - ]]; then
- _message 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
+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
+ ;;
+ 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
- _groups && return 0
- else
- if [[ $OSTYPE = (solaris*|hpux*|*bsd*) ]]; then
- suf=':'
+ 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 )
+ [[ -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})"
- _wanted files expl file _files -g "*(${(j:,:)req})" && return 0
-fi
+ ( : $~req ) 2> /dev/null || req='*'
+
+ _wanted files expl file _files -g "$req" && ret=0
+ ;;
+esac
+
+return ret