* [patch] Don't leak a function from _chflags
@ 2017-12-13 5:00 Matthew Martin
0 siblings, 0 replies; only message in thread
From: Matthew Martin @ 2017-12-13 5:00 UTC (permalink / raw)
To: zsh-workers
Slightly under a year ago Daniel mentioned in workers/40212 that
_chflags shouldn't define a function in the user's namespace. This
changes it to an anonymous function sidestepping any namespace concerns.
Also reorder _arguments arguments, so flags are completed after -h.
- Matthew Martin
diff --git a/Completion/BSD/Command/_chflags b/Completion/BSD/Command/_chflags
index 075782cd9..ddf61b25e 100644
--- a/Completion/BSD/Command/_chflags
+++ b/Completion/BSD/Command/_chflags
@@ -1,65 +1,69 @@
#compdef chflags
-local flags args own='-g *(-u$EUID)'
+local args flag_descs flags own='-g *(-u$EUID)'
-addflags() {
- for 1 2; do
- if [[ $1 = no* ]]; then
- flags+=("(${1#no})$1[set the $2 flag]"
- "($1)${1#no}[unset the $2 flag]")
- else
- flags+=("(no$1)$1[set the $2 flag]"
- "($1)no$1[unset the $2 flag]")
- fi
- done
-}
-
-addflags \
- uappnd 'user append-only' \
+flag_descs=(
+ uappnd 'user append-only'
uchg 'user immutable'
+)
if (( ! EUID )); then
- addflags \
- arch archived \
- nodump nodump \
- sappnd 'system append-only' \
+ flag_descs+=(
+ arch archived
+ nodump nodump
+ sappnd 'system append-only'
schg 'system immutable'
+ )
unset own
fi
if [[ $OSTYPE = (darwin|dragonfly|freebsd|netbsd)* ]]; then
- addflags opaque opaque
+ flag_descs+=(opaque opaque)
if [[ $OSTYPE = darwin* ]]; then
- addflags hidden hidden
+ flag_descs+=(hidden hidden)
fi
if [[ $OSTYPE = (dragonfly|freebsd)* ]]; then
- addflags uunlnk 'user undeletable'
- (( EUID )) || addflags sunlnk 'system undeletable'
+ flag_descs+=(uunlnk 'user undeletable')
+ (( EUID )) || flag_descs+=(sunlnk 'system undeletable')
fi
[[ $OSTYPE = dragonflybsd* ]] && {
- addflags \
- cache XXX \
+ flag_descs+=(
+ cache XXX
nouhistory 'user nohistory'
+ )
- (( EUID )) || addflags \
- noscache XXX \
+ (( EUID )) || flag_descs+=(
+ 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' \
+ [[ $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]"
+ "($1)${1#no}[unset the $2 flag]")
+ else
+ flags+=("(no$1)$1[set the $2 flag]"
+ "($1)no$1[unset the $2 flag]")
+ fi
+ done
+} $flag_descs
+
if [[ $OSTYPE = (darwin|dragonfly|freebsd)* ]]; then
args=(
"-f[don't display diagnostic messages]"
@@ -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)]'
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2017-12-13 5:01 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-13 5:00 [patch] Don't leak a function from _chflags Matthew Martin
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).