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

Re: Prompt expansion on signals



On Sun, Nov 28, 2021 at 2:01 AM Roman Perepelitsa
<roman.perepelitsa@xxxxxxxxx> wrote:
>
> For this to work correctly, prompt_subst must be set when prompt is
> expanded. However, this requirement can be violated when prompt is
> expanded in a signal handler.

A more egregious example might be when the global settings have
"unsetopt promptpercent".

Are prompts the only case where this is an issue, though?  The most
visible, certainly, but "zle -F" for example?

What about the reverse situation, where the signal handler is a
function that changes options locally?

> Prompt expansion can be affected by options other than prompt_*.

Are you aware of any cases where this is true but prompt_subst is false?

> Is there a solution for this problem that I'm missing? Are there
> workarounds? How could it be fixed?

I can't think of any workaround, other than perhaps to create a signal
handler that does "zle -I" ... as to a possible fix, since the prompt
parameters are all specials they could be programmed to memoize the
options in effect at the time they are assigned, similar to the way
functions can have "sticky" options when defined within an "emulate
-c", and restore those before expansion.  That introduces several
other questions:  Can each prompt have different options (e.g., RPS1
differ from PS1)?  If a prompt parameter is assigned within a
function, does it memoize the local options?  If PS1 et al. are
imported from the environment, what options are initially memoized and
when?

Perhaps the prompt options should be excluded from those altered by
"emulate -R"?  "... except for certain options describing the
interactive environment ... only those options likely to cause
portability problems in scripts and functions are altered ..."  Are
promptsubst and promptpercent etc. "likely to cause portability
problems"?  I suppose they are if a "select" statement is used and PS3
has been changed.  Either way that doesn't fix an explicit setopt of
those.




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