From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15626 invoked by alias); 13 Dec 2017 05:01:09 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 42117 Received: (qmail 16673 invoked by uid 1010); 13 Dec 2017 05:01:09 -0000 X-Qmail-Scanner-Diagnostics: from mail-ot0-f182.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(74.125.82.182):SA:0(-1.7/5.0):. Processed in 1.444817 secs); 13 Dec 2017 05:01:09 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_PASS,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.1 X-Envelope-From: phy1729@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | 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== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mail-followup-to :mime-version:content-disposition:user-agent; bh=TY/p3MlpQmPFUN9v/ui71Q0br5BZrowjsoiNIa5d5tw=; b=DCeEQyIV4Gx+nrELDtShsdsWN2wEi1JxOYJK9Ee5C6vDjNBjnlalDt/FXGuqo8DVeG o4QUj3izY53B7qm8XvL0OqjKn8X/IeMaNeH3vIaJuZAjw5fYYIFMInQSyx2Z662DnkGG y9GpQKWjYHkPaYdTISpo8Q4RneEXZpt1qvFUGAcJ/ln6yVyrQLIo41QzQ+h7y2SYOVVv pKg2Q2v+39gScz5Rn+y0hMjiPy5OztQ5XnKpcOEM7w89dC0VfznM3b/TEZz3NzMXPqP9 FtfGul4EKWaKzD9Lwz6lC4mbEDV3sTtry3LpL2cBGHEvrsmYcykrhpF0zVkl/qBBJrpG p5yQ== X-Gm-Message-State: AKGB3mJdZzaG8HfT+pW8wT7aUHcy5ezug9njj+wPBTyo/od15ew/AiNV 0OITAXkFWUKPWLlwq7pakPyc4fx4 X-Google-Smtp-Source: ACJfBouIFGIwUDJ4plw05Dh8aGJNg2A+A0d4WcH7khvMqvQh6sfnQs9euZNixJc/N0JNIsuhvaHHEA== X-Received: by 10.157.85.221 with SMTP id z29mr1110463oti.14.1513141263630; Tue, 12 Dec 2017 21:01:03 -0800 (PST) Date: Tue, 12 Dec 2017 23:00:59 -0600 From: Matthew Martin To: zsh-workers@zsh.org Subject: [patch] Don't leak a function from _chflags Message-ID: <20171213050059.GA7970@CptOrmolo.darkstar> Mail-Followup-To: zsh-workers@zsh.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.1 (2017-09-22) 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)]'