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

Re: Prompt expansion on signals

On Sun, Nov 28, 2021 at 10:10 PM Oliver Kiddle <opk@xxxxxxx> wrote:
> Roman Perepelitsa wrote:
> > I sometimes change prompt_* options in functions when I want to use `print -P`.
> >
> >     emulate -L zsh -o prompt_percent no_prompt_subst
> >     print -Pru2 -- '%F{1}error%f: missing required parameter: %F{3}--foo%f'
> In some cases, you might be better off using the ${(%)var} prompt
> expansion.

I do this in a few places. I'll probably need to replace all `print
-P` calls with ${(%)} expansions.

As a last resort I'm also considering removing all `emulate -L zsh`
calls from all my code and not using any functions from third-parties
or shipped with zsh, however awful that sounds.

> It isn't necessarily just hooks and signal handlers that are affected.

What do you mean by hooks? The only two places where I don't know how
to control options is prompt expansion on SIGWINCH and SIGCHLD. Are
there more?

> Someone might want to use emulate in a zle widget directly. If this is a
> plugin, and the author uses default prompt options, it mightn't be clear
> to them that this could break for other users.

What do you mean? Is it the same problem or a different one?

Maybe we are talking about different things. Let's assume I'm in
control of all my rc files and their complete transitive closure. I'm
writing all widgets by hand. Every line of zsh code that executes in
my shell is written by me. Given this assumption, I would like to
avoid prompt expansion with wrong options. Right now the only way I
know how to achieve this is to either give up perf-function options
(via local_options + whatever options I want in the function) or to
avoid triggering SIGWINCH and SIGCHLD (which implies never resizing my
terminal and not using background jobs).

> There are some cases in completion too where it'd be useful to restore
> the user's option settings for a particular command. Perhaps we could
> have an argument to emulate - user or global perhaps - for restoring the
> original options.

Would this help in avoiding prompt expansion with incorrect options?

> Making options sticky when PS1, PS2 etc are set might break someone's
> setup where they set their prompt before their options.

Good point.

Making options sticky also wouldn't avoid the issue where prompt is
expanded with incorrect special parameters (LC_ALL, etc.). Overriding
special parameters as locals in functions is convenient. It's a shame
that it has the side effect of introducing a race that breaks prompt.

Is there a downside to postponing the handling of SIGCHLD and SIGWINCH
until all functions return? Postponing SIGWINCH seems safe but
postponing SIGCHLD might blow up the job table. Is this a serious


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