Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Evaluating parameters in general-purpose widgets

Bart Schaefer wrote on Thu, 18 Jan 2018 22:25 -0800:
> On Thu, Jan 18, 2018 at 4:21 PM, Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
> >
> > Is it safe for zsh-syntax-highlighting to evaluate parameter expansions
> > in the input?
> Depending on how costly you're willing to make this, you could always
> use "${$(print -nr -- "$foobar"X)%X}" to assure the parameter is
> evaluated where it can't have any effects on the current shell.

That's a handy idiom :-).

In this case, however, I can think of two issues with it: it wouldn't be
performant on platforms where fork() is expensive, and it would mess
with modules-provided parameters whose getfn uses out-of-process state.

Therefore, I'm currently inclined to
    if $parameters[foobar] == *special* ; then
        # leave it alone
        # expand it using ${(P)${:-foobar}}
to sidestep module-provided parameters entirely.



P.S. For anyone else reading this: using ${(P)} like that is only
     correct when SH_WORD_SPLIT hasn't been set.

Messages sorted by: Reverse Date, Date, Thread, Author