1
0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-10-02 08:51:18 +02:00
zsh/Completion/Unix/Command/_chown
2001-07-17 11:06:24 +00:00

34 lines
906 B
Plaintext

#compdef chown chgrp
local suf usr grp req expl
if [[ CURRENT -eq 2 || CURRENT -eq 3 && $words[CURRENT-1] = -* ]]; then
if [[ $service = chgrp ]] || compset -P '*[:.]'; then
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*|*bsd*) ]]; then
suf=':'
else
suf='.'
fi
compset -S '.*' && unset suf
_users -S "$suf" -q && return 0
fi
else
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