Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Bug report: `setopt noaliases` not respected in `local` statement without assignment.
- X-seq: zsh-workers 45632
- From: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>
- To: Marlon Richert <marlon.richert@xxxxxxxxx>
- Subject: Re: Bug report: `setopt noaliases` not respected in `local` statement without assignment.
- Date: Thu, 26 Mar 2020 11:38:34 +0100
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- In-reply-to: <CAHLkEDurch52306wHG4q6QWt-VXxMmtJSWhBE0s-JU=wTf-VdA@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CAHLkEDu76YfBKX+47pT58VAMHd=Ep7JDq8K+3jYBYCAx+W5GKA@mail.gmail.com> <CAN=4vMq_EAtuj-K9P9FpmGADX_ER5msF5aFL6MtKhcT6O+dXxQ@mail.gmail.com> <CAHLkEDurch52306wHG4q6QWt-VXxMmtJSWhBE0s-JU=wTf-VdA@mail.gmail.com>
On Thu, Mar 26, 2020 at 11:27 AM Marlon Richert
<marlon.richert@xxxxxxxxx> 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 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+=('aliases')
[[ ! -o 'sh_glob' ]] || _fzf_completion_opts+=('sh_glob')
[[ ! -o 'no_brace_expand' ]] || _fzf_completion_opts+=('no_brace_expand')
'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 <roman.perepelitsa@xxxxxxxxx> wrote:
>>
>> On Thu, Mar 26, 2020 at 10:55 AM Marlon Richert
>> <marlon.richert@xxxxxxxxx> wrote:
>> >
>> > Test case:
>> >
>> > alias -g tail="multitail -Cs --follow-all"
>> > f() {
>> > setopt localoptions no_aliases
>> > local tail
>> > tail=1
>> > 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=1
>> > echo $tail
>> > }
>>
>> `tail` within `local tail=1` is not subject to global alias expansion.
>>
>> Roman.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author