From dd824080cacd64289281ae6088732d6b63942728 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Tue, 12 Dec 2017 23:00:59 -0600 Subject: 42117: use anonymous function rather than define one in user namespace --- Completion/BSD/Command/_chflags | 80 +++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 38 deletions(-) (limited to 'Completion/BSD') 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)]' -- cgit 1.4.1