1
0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-10-02 17:01:19 +02:00

complete only files that can be chowned (14282)

This commit is contained in:
Oliver Kiddle 2001-05-09 15:27:01 +00:00
parent e364fb2139
commit 7f4eb97085
2 changed files with 21 additions and 4 deletions

@ -1,5 +1,8 @@
2001-05-09 Oliver Kiddle <opk@zsh.org>
* 14282: Completion/Unix/Command/_chown: complete only files
that can be chowned.
* 14281: Completion/Base/Completer/_expand: insert redirection
operators when expanding after a redirection operator.

@ -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