mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-29 19:00:57 +02:00
new chmod completion
This commit is contained in:
parent
74678a3435
commit
280593163d
3 changed files with 87 additions and 0 deletions
|
@ -1,3 +1,7 @@
|
|||
2003-08-01 Oliver Kiddle <opk@zsh.org>
|
||||
|
||||
* 18xxx: Completion/Unix/Command/_chmod: new chmod completion
|
||||
|
||||
2003-08-01 Peter Stephenson <pws@csr.com>
|
||||
|
||||
* 18916: Src/utils.c: Unsetting IFS could cause segmentation
|
||||
|
|
|
@ -21,4 +21,5 @@ _netcat _larch _texinfo _figlet _elinks _tidy
|
|||
_global _ant _lsof _mt _xmlsoft
|
||||
_perforce _python _antiword _screen _renice _apm
|
||||
_ecasound _gpg _subversion _aap _sablotron _nmap
|
||||
_chmod
|
||||
'
|
||||
|
|
82
Completion/Unix/Command/_chmod
Normal file
82
Completion/Unix/Command/_chmod
Normal file
|
@ -0,0 +1,82 @@
|
|||
#compdef chmod
|
||||
|
||||
local curcontext="$curcontext" state line ret=1
|
||||
local -a args privs
|
||||
|
||||
args=( '*:file:->files' )
|
||||
(( $+words[(r)--reference*] )) || args+=( '1:mode:->mode' )
|
||||
|
||||
if _pick_variant gnu=Free\ Soft unix --version; then
|
||||
args+=(
|
||||
'(-v --verbose -c --changes)'{-c,--changes}'[report changes made]'
|
||||
'(-v --verbose -c --changes)'{-v,--verbose}'[output a diagnostic for every file processed]'
|
||||
'(-f --silent --quiet)'{-f,--silent,--quiet}'[suppress most error messages]'
|
||||
'--reference=[copy permissions of specified file]:file:_files'
|
||||
'(-R --recursive)'{-R,--recursive}'[change files and directories recursively]'
|
||||
'(- : *)--help[display help information]'
|
||||
'(- : *)--version[display version information]'
|
||||
)
|
||||
privs=(
|
||||
'X[execute only if executable to another]'
|
||||
"u[owner's current permissions]"
|
||||
"g[group's current permissions]"
|
||||
"o[other's current permissions]"
|
||||
)
|
||||
else
|
||||
# based on $OSTYPE = solaris2.8
|
||||
args+=(
|
||||
'-f[suppress most error messages]'
|
||||
'-R[change files and directories recursively]'
|
||||
)
|
||||
privs=( 'l[mandatory locking]' )
|
||||
fi
|
||||
|
||||
_arguments -C -s "$args[@]" && ret=0
|
||||
|
||||
case "$state" in
|
||||
mode)
|
||||
compset -P \*,
|
||||
compset -S ,\*
|
||||
if [[ -prefix [0-7] ]]; then
|
||||
_message -e number 'numeric mode'
|
||||
elif compset -P '[a-z]#[+-=]'; then
|
||||
_values -S '' privilege \
|
||||
'r[read]' 'w[write]' 'x[execute]' \
|
||||
's[set uid/gid]' 't[sticky]' \
|
||||
"$privs[@]" && ret=0
|
||||
else
|
||||
suf=( -S '' )
|
||||
compset -P '*'
|
||||
_alternative -O suf \
|
||||
'who:who:((u\:user g\:group a\:all o\:others))' \
|
||||
'operators:operator:(+ - =)'
|
||||
fi
|
||||
;;
|
||||
files)
|
||||
if [[ -n $opt_args[--reference] ]]; then
|
||||
if zstyle -t ":completion:${curcontext}:" disable-stat; then
|
||||
_files && ret=0
|
||||
else
|
||||
zmodload -i zsh/stat 2>/dev/null
|
||||
typeset -i8 ref=$(stat +mode $opt_args[--reference])
|
||||
_wanted files expl file _files -g "*(-.^f${ref#??})" && ret=0
|
||||
fi
|
||||
elif [[ $words[2] = [0-7]## ]]; then
|
||||
_wanted files expl file _files -g "*(-.^f$words[2])" && ret=0
|
||||
else
|
||||
local spec who op priv
|
||||
local -a specs
|
||||
for spec in ${(s:,:)words[2]}; do
|
||||
if [[ ${spec#*[+-=]} != [rwxst]* ]]; then
|
||||
_files && ret=0
|
||||
return ret
|
||||
fi
|
||||
|
||||
specs+=( ${${(M)spec##[+-=]*}:+a}$spec )
|
||||
done
|
||||
_wanted files expl file _files -g "*(-.^f:${(j.,.)specs}:)" && ret=0
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
return ret
|
Loading…
Reference in a new issue