about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthew Martin <phy1729@gmail.com>2017-12-12 23:00:59 -0600
committerOliver Kiddle <opk@zsh.org>2018-01-03 17:11:00 +0100
commitdd824080cacd64289281ae6088732d6b63942728 (patch)
treeacd25371bd2ca7bc8c7b876d8180b05a15a05d83
parent99cf61fd4211dcb99142f683230947481c05eb93 (diff)
downloadzsh-dd824080cacd64289281ae6088732d6b63942728.tar.gz
zsh-dd824080cacd64289281ae6088732d6b63942728.tar.xz
zsh-dd824080cacd64289281ae6088732d6b63942728.zip
42117: use anonymous function rather than define one in user namespace
-rw-r--r--ChangeLog9
-rw-r--r--Completion/BSD/Command/_chflags80
2 files changed, 49 insertions, 40 deletions
diff --git a/ChangeLog b/ChangeLog
index 4f7ce2992..10473ff7c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
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)]'