Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[patch] Don't leak a function from _chflags
- X-seq: zsh-workers 42117
- From: Matthew Martin <phy1729@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: [patch] Don't leak a function from _chflags
- Date: Tue, 12 Dec 2017 23:00:59 -0600
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mail-followup-to:mime-version :content-disposition:user-agent; bh=TY/p3MlpQmPFUN9v/ui71Q0br5BZrowjsoiNIa5d5tw=; b=mmNek/gAm4JXBkSinvg2kesfv37rbQdO+5bn21l4KQU9vPlvSGuP5KRwgoc7X4pYhm 3cUiF96lzTshce38o+lZg66Odi7B6Y51LdBJz17WyJJVeZy8TL6fRFCV5cpWSBwdwX5r rHfGcEx4a/ztiLaKdaba2IpgIuxoH4P0bjnYEpmO09iqOjl6sPyefus3QpmFkLyKQOu4 Wnx0SE2xI4bAh3Q+xOOm7roPzDLFmg3BzUinjAE0MxBu2+8DIsovLWlDGGWZVqrrgp/y 5T8ZiqwJyxRdnqB6d2wSwEvtvjpahgqXLNnOsmlmSsJGs55eDJBBSh6JqfVOb4MEoWRk b3Mw==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mail-followup-to: zsh-workers@xxxxxxx
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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)]'
Messages sorted by:
Reverse Date,
Date,
Thread,
Author