From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RDNS_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 Received: (qmail 2660 invoked from network); 26 Mar 2020 10:39:28 -0000 Received-SPF: pass (primenet.com.au: domain of zsh.org designates 203.24.36.2 as permitted sender) receiver=inbox.vuxu.org; client-ip=203.24.36.2 envelope-from= Received: from unknown (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTP; 26 Mar 2020 10:39:28 -0000 Received: (qmail 27015 invoked by alias); 26 Mar 2020 10:39:21 -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: 45632 Received: (qmail 17104 invoked by uid 1010); 26 Mar 2020 10:39:21 -0000 X-Qmail-Scanner-Diagnostics: from mail-io1-f68.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.2/25758. spamassassin: 3.4.2. Clear:RC:0(209.85.166.68):SA:0(-2.0/5.0):. Processed in 2.676562 secs); 26 Mar 2020 10:39:21 -0000 X-Envelope-From: roman.perepelitsa@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.166.68 as permitted sender) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=Wzdf8GTWIa+KbippdShYwfsjhiCwbzGbiucLsyCVsI4=; b=KVKQGAx7t43/BWKAtZwBtDyrVp0/G3DMwpN5kIW/ShRlygmc5YVVV4YQkY4D/8yDvR CvB5C6hqH/7cexj5nhEnnV40Nk4LRENfAFUwwOcM4PWowfvOH3eg/d4q1Edo+SCW1RIN l5n56c/cAnx7/U7fwh+uAr2mBgURuCeZtyGYI8aV6b83NVzHv7E9dF14yQ+ulC28jNCU KilkPRqq43XXOb6tb7CzCD6f+rz8BtRgx9zJwP2aJXmi9wpB6ysFcPNv+/eRhhrM5m19 KiQ0DrhKAsI9v3f/UI5KU1hoVzJTI+/2BEsehB9mRR2STJZnF2GB4vMyzvFKoPnjwvBd xFiQ== X-Gm-Message-State: ANhLgQ0ujN8RmFjvtCCceU8o/zB2Qd1mZxU9+6K23m5uoKu5wY/UgtYa vjQXvf+n3o75AQDtiv8ZfLzYake7PkqdvDC3ZRw= X-Google-Smtp-Source: ADFU+vuSibKV8wkD2VjnzRk5f2OCNLGl2x7dZnyGmv1U6oB7OIJU8rWzTzZqWnzVjOPSpprYn+0P6SBn55hBjAtPUgM= X-Received: by 2002:a6b:b747:: with SMTP id h68mr7142409iof.105.1585219125895; Thu, 26 Mar 2020 03:38:45 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Roman Perepelitsa Date: Thu, 26 Mar 2020 11:38:34 +0100 Message-ID: Subject: Re: Bug report: `setopt noaliases` not respected in `local` statement without assignment. To: Marlon Richert Cc: Zsh hackers list Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Mar 26, 2020 at 11:27 AM Marlon Richert wrote: > > Aha. So, if I want that aliases don't get expanded in the functions in ht= tps://github.com/junegunn/fzf/blob/master/shell/completion.zsh, then where = should I put the `setopt noaliases` statement? Does it suffice to just put = `emulate -L zsh; setopt localoptions noaliases;` at the top of the file? I = don't want the noaliases option to leak into my own shell environment. > > Or is there a better solution possible here than using noaliases? The official solution to this problem is to use autoloadable functions instead of sourcing zsh scripts with function definitions. One practical alternative is to add a bit of code at the top and at the bottom of completion.zsh. Like this: 'builtin' 'local' '-a' '_fzf_completion_opts' [[ ! -o 'aliases' ]] || _fzf_completion_opts+=3D('aliases') [[ ! -o 'sh_glob' ]] || _fzf_completion_opts+=3D('sh_glob') [[ ! -o 'no_brace_expand' ]] || _fzf_completion_opts+=3D('no_brace_expa= nd') 'builtin' 'setopt' 'no_aliases' 'no_sh_glob' 'brace_expand' # the meat of completion.zsh goes here (( ${#_fzf_completion_opts} )) && setopt ${_fzf_completion_opts[@]} 'builtin' 'unset' '_fzf_completion_opts' Note that this doesn't just disable aliases but also changes a couple other options that similarly affect parsing of functions. (You could also wrap the whole script in try-always to make sure options are restored even if evaluation of the script stops prematurely.) Another alternative is to rename completion.zsh to internal-completion.zsh and place this shim in place of the original completion.zsh: 'builtin' 'emulate' 'zsh' '-o' 'no_aliases' '-c' 'builtin source ${${(%):-%x}:h}/internal-completion.zsh' Roman. > On Thu, 26 Mar 2020 at 11:59, Roman Perepelitsa wrote: >> >> On Thu, Mar 26, 2020 at 10:55 AM Marlon Richert >> wrote: >> > >> > Test case: >> > >> > alias -g tail=3D"multitail -Cs --follow-all" >> > f() { >> > setopt localoptions no_aliases >> > local tail >> > tail=3D1 >> > echo $tail >> > } >> >> Alias expansion happens when functions get parsed. If you don't want >> `tail` to be alias-expanded within function `f`, you need to add >> `setopt no_aliases` before the function of `f`. >> >> > g() { >> > setopt localoptions no_aliases >> > local tail=3D1 >> > echo $tail >> > } >> >> `tail` within `local tail=3D1` is not subject to global alias expansion. >> >> Roman.