Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: view onto command pipeline?
On Wed, Jul 20, 2022, at 10:11 PM, Anthony Heading wrote:
> On Wed, Jul 20, 2022, at 9:35 PM, Lawrence Velázquez wrote:
>> Leaving $opts[@] unquoted still elides empty elements in this
>> context; that behavior is not limited to $@. (If this is what you
>> actually want, go for it. Just don't think that fiddling with
>> options has an effect.)
>>
>
> Yes indeed! Though recall the context here was a *fixed* *literal* array:
> opts=(-c color.ui=always)
> command git $opts "$@"
>
> Quoting "$@" agreed, but writing "${opts[@]}" instead here seems
> a little bit like self-flagellation, no?
Sure, it doesn't matter for this particular case. I didn't notice
that you were hardcoding the array contents.
>> It's better to run ''emulate -L zsh'' inside the function itself
>> (or localize and [un]set options individually as desired) to achieve
>> a known state, rather than relying on a specific method of invocation.
>
> Oh, interesting! why is that? Certainly want to get the most
> stable state. I do vaguely remember tricky corner cases being discussed
> on zsh-workers maybe decades ago, but it seems to work great now.
> And, unless I picked up this autoload idiom from the mailing list,
> I think it's from the man pages somewhere. If you're advising that
> it's sub-optimal, should it be removed or caveated in the documentation?
I assume you're referring to this
(https://zsh.sourceforge.io/Doc/Release/Shell-Builtin-Commands.html#index-autoload):
Note that the autoload command makes no attempt to ensure the shell
options set during the loading or execution of the file have any
particular value. For this, the emulate command can be used:
emulate zsh -c 'autoload -Uz func'
arranges that when func is loaded the shell is in native zsh
emulation, and this emulation is also applied when func is run.
I'm not saying there's anything incorrect here. I imagine it's
useful if you're using functions written by others that break due
to options you've set or unset in your own environment.
What I'm saying is that if you are writing your own functions, you
should try to write them so they proactively establish whatever
state they require, instead of punting that responsibility to the
caller. (This is just common sense.) If you need many options to
have their zsh-native default values, then it generally suffices
to call
emulate -L zsh
at the beginning of the function.
--
vq
Messages sorted by:
Reverse Date,
Date,
Thread,
Author