1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-03 10:21:46 +02:00

42117: use anonymous function rather than define one in user namespace

This commit is contained in:
Matthew Martin 2017-12-12 23:00:59 -06:00 committed by Oliver Kiddle
parent 99cf61fd42
commit dd824080ca
2 changed files with 63 additions and 54 deletions

View file

@ -1,4 +1,9 @@
2017-01-02 Eric Cook <llua@gmx.com>
2018-01-03 Oliver Kiddle <okiddle@yahoo.co.uk>
* Matthew Martin: 42117: Completion/BSD/Command/_chflags:
use anonymous function rather than define one in user namespace
2018-01-02 Eric Cook <llua@gmx.com>
* 42171: Completion/BSD/Command/_portsnap,
Completion/Linux/Command/_ipset,
@ -112,7 +117,7 @@
2017-12-13 Peter Stephenson <p.w.stephenson@ntlworld.com>
* Matthew Martin: 42113: Completion/BSD/Command/_bsd_pkg,
* Matthew Martin: 42114: Completion/BSD/Command/_bsd_pkg,
Completion/BSD/Type/_fbsd_architectures,
Completion/BSD/Type/_nbsd_architectures,
Completion/BSD/Type/_obsd_architectures: Remove FreeBSD use of

View file

@ -1,8 +1,58 @@
#compdef chflags
local flags args own='-g *(-u$EUID)'
local args flag_descs flags own='-g *(-u$EUID)'
addflags() {
flag_descs=(
uappnd 'user append-only'
uchg 'user immutable'
)
if (( ! EUID )); then
flag_descs+=(
arch archived
nodump nodump
sappnd 'system append-only'
schg 'system immutable'
)
unset own
fi
if [[ $OSTYPE = (darwin|dragonfly|freebsd|netbsd)* ]]; then
flag_descs+=(opaque opaque)
if [[ $OSTYPE = darwin* ]]; then
flag_descs+=(hidden hidden)
fi
if [[ $OSTYPE = (dragonfly|freebsd)* ]]; then
flag_descs+=(uunlnk 'user undeletable')
(( EUID )) || flag_descs+=(sunlnk 'system undeletable')
fi
[[ $OSTYPE = dragonflybsd* ]] && {
flag_descs+=(
cache XXX
nouhistory 'user nohistory'
)
(( EUID )) || flag_descs+=(
noscache XXX
noshistory 'system nohistory'
)
}
[[ $OSTYPE = freebsd* ]] && flag_descs+=(
uarch archive
uhidden hidden
uoffline offline
urdonly 'DOS, Windows and CIFS readonly'
ureparse 'Windows reparse point'
usparse 'sparse file'
usystem 'DOS, Windows and CIFS system'
)
fi
() {
for 1 2; do
if [[ $1 = no* ]]; then
flags+=("(${1#no})$1[set the $2 flag]"
@ -12,53 +62,7 @@ addflags() {
"($1)no$1[unset the $2 flag]")
fi
done
}
addflags \
uappnd 'user append-only' \
uchg 'user immutable'
if (( ! EUID )); then
addflags \
arch archived \
nodump nodump \
sappnd 'system append-only' \
schg 'system immutable'
unset own
fi
if [[ $OSTYPE = (darwin|dragonfly|freebsd|netbsd)* ]]; then
addflags opaque opaque
if [[ $OSTYPE = darwin* ]]; then
addflags hidden hidden
fi
if [[ $OSTYPE = (dragonfly|freebsd)* ]]; then
addflags uunlnk 'user undeletable'
(( EUID )) || addflags sunlnk 'system undeletable'
fi
[[ $OSTYPE = dragonflybsd* ]] && {
addflags \
cache XXX \
nouhistory 'user nohistory'
(( EUID )) || addflags \
noscache XXX \
noshistory 'system nohistory'
}
[[ $OSTYPE = freebsd* ]] && addflags \
uarch archive \
uhidden hidden \
uoffline offline \
urdonly 'DOS, Windows and CIFS readonly' \
ureparse 'Windows reparse point' \
usparse 'sparse file' \
usystem 'DOS, Windows and CIFS system'
fi
} $flag_descs
if [[ $OSTYPE = (darwin|dragonfly|freebsd)* ]]; then
args=(
@ -68,12 +72,12 @@ if [[ $OSTYPE = (darwin|dragonfly|freebsd)* ]]; then
fi
_arguments -s -A "-*" : $args \
':file flag:_values -s , "file flags" $flags[@]' \
'*:file:_files "$own"' \
- opth \
'-h[act on symlinks]' \
- optR \
'-R[recurse directories]' \
'(-L -P)-H[follow symlinks on the command line (specify with -R)]' \
'(-H -P)-L[follow all symlinks (specify with -R)]' \
'(-L -H)-P[do not follow symlinks (specify with -R)]' \
':file flag:_values -s , "file flags" $flags[@]' \
'*:file:_files "$own"'
'(-L -H)-P[do not follow symlinks (specify with -R)]'