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=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,RDNS_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 Received: (qmail 26153 invoked from network); 26 Mar 2020 22:35:39 -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 22:35:39 -0000 Received: (qmail 27761 invoked by alias); 26 Mar 2020 22:35:32 -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: 45638 Received: (qmail 1327 invoked by uid 1010); 26 Mar 2020 22:35:31 -0000 X-Qmail-Scanner-Diagnostics: from out4-smtp.messagingengine.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(66.111.4.28):SA:0(-2.6/5.0):. Processed in 3.771244 secs); 26 Mar 2020 22:35:31 -0000 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at daniel.shahaf.name does not designate permitted sender hosts) X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrudehjedgleelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfgjfhfogggtgfesthhqtddtredtjeenucfhrhhomhepffgrnhhi vghlucfuhhgrhhgrfhcuoegurdhssegurghnihgvlhdrshhhrghhrghfrdhnrghmvgeqne cuffhomhgrihhnpehgihhthhhusgdrtghomhdpiihshhdrlhhikhgvnecukfhppeejledr udejiedruddvhedrvdefvdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpegurdhssegurghnihgvlhdrshhhrghhrghfrdhnrghmvg X-ME-Proxy: Date: Thu, 26 Mar 2020 22:34:49 +0000 From: Daniel Shahaf To: Roman Perepelitsa Cc: Marlon Richert , Zsh hackers list Subject: Re: Bug report: `setopt noaliases` not respected in `local` statement without assignment. Message-ID: <20200326223449.0a090ae6@tarpaulin.shahaf.local2> In-Reply-To: References: X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Roman Perepelitsa wrote on Thu, 26 Mar 2020 11:38 +0100: > 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 = https://github.com/junegunn/fzf/blob/master/shell/completion.zsh, then wher= e should I put the `setopt noaliases` statement? Does it suffice to just pu= t `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? =20 >=20 > The official solution to this problem is to use autoloadable functions > instead of sourcing zsh scripts with function definitions. >=20 Note that the -U flag should be passed to =C2=ABautoload=C2=BB in that case. > One practical alternative is to add a bit of code at the top and at > the bottom of completion.zsh. Like this: >=20 > '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_ex= pand') > 'builtin' 'setopt' 'no_aliases' 'no_sh_glob' 'brace_expand' >=20 > # the meat of completion.zsh goes here >=20 > (( ${#_fzf_completion_opts} )) && setopt ${_fzf_completion_opts[@]} > 'builtin' 'unset' '_fzf_completion_opts' >=20 z-sy-h does something similar with aliases: https://github.com/zsh-users/zsh-syntax-highlighting/blob/d1802e388e94aca25= 380a3a9aeb4a2b7ba661b41/zsh-syntax-highlighting.zsh#L30-L36 =E2=8B=AE https://github.com/zsh-users/zsh-syntax-highlighting/blob/d1802e388e94aca25= 380a3a9aeb4a2b7ba661b41/zsh-syntax-highlighting.zsh#L442-L444 For options, z-sy-h uses =C2=ABemulate -L=C2=BB for the vast majority of its code. It's on our todo list (issue #688) to add a =C2=ABemulate zsh -o =E2= =80=A6 -c 'source =E2=80=A6'=C2=BB shim around the entry point script, as Roman pr= oposes below. > 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.) >=20 There are a few other options to worry about, e.g., KSH_ARRAYS, IGNORE_CLOES_BRACES. > Another alternative is to rename completion.zsh to > internal-completion.zsh and place this shim in place of the original > completion.zsh: >=20 > 'builtin' 'emulate' 'zsh' '-o' 'no_aliases' '-c' 'builtin source > ${${(%):-%x}:h}/internal-completion.zsh' >=20 > Roman. >=20 Cheers, Daniel >=20 >=20 >=20 > > On Thu, 26 Mar 2020 at 11:59, Roman Perepelitsa wrote: =20 > >> > >> On Thu, Mar 26, 2020 at 10:55 AM Marlon Richert > >> wrote: =20 > >> > > >> > Test case: > >> > > >> > alias -g tail=3D"multitail -Cs --follow-all" > >> > f() { > >> > setopt localoptions no_aliases > >> > local tail > >> > tail=3D1 > >> > echo $tail =20 > >> > } =20 > >> > >> 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`. > >> =20 > >> > g() { > >> > setopt localoptions no_aliases > >> > local tail=3D1 > >> > echo $tail =20 > >> > } =20 > >> > >> `tail` within `local tail=3D1` is not subject to global alias expansio= n. > >> > >> Roman. =20