Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Prompt expansion on signals
- X-seq: zsh-workers 49610
- From: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: Prompt expansion on signals
- Date: Sun, 28 Nov 2021 21:31:54 +0100
- Archived-at: <https://zsh.org/workers/49610>
- In-reply-to: <CAH+w=7at6wN1VfWA7=_HEuaHkCREBfES=Z5sTrHrBY4n2SR9YA@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAN=4vMoLqgFjKnWUCH0ZxzEfszpO0ccOEneed9B3aNC_+t3HXg@mail.gmail.com> <CAH+w=7at6wN1VfWA7=_HEuaHkCREBfES=Z5sTrHrBY4n2SR9YA@mail.gmail.com>
On Sun, Nov 28, 2021 at 8:50 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> 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".
I can control these in my config. I cannot control options that are
active when zsh processes SIGCHLD though (unless I never change
options in zle widgets).
To clarify, I'd like to:
1. Be able to resize my terminal and run background jobs.
2. Use zle widgets that set local_options and any other options
together with it.
3. Never have my prompt expanded with wrong options.
I don't know how to satisfy all three. If I drop the first point, then
I do know. That is, I have control of shell options in all cases
except when zsh expands prompt in a signal handler.
These requirements look reasonable to me. Isn't it something that
virtually everyone wants? I was surprised when I realized that I
cannot have these things simultaneously (or don't know how).
> Are prompts the only case where this is an issue, though? The most
> visible, certainly, but "zle -F" for example?
As far as I'm aware, prompt expansion on signals is the only place
where it's impossible to set options. Perhaps I'm misunderstanding
what you mean by "zle -F" in this context?
> What about the reverse situation, where the signal handler is a
> function that changes options locally?
What do you mean?
> > 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?
Hm... multibyte? There are also special parameters like LC_ALL that
cause the same issue. For example, doing the following in a widget can
break prompt if SIGCHLD arrives at the wrong moment:
local LC_ALL=C
...
> Either way that doesn't fix an explicit setopt of those.
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'
This seemed smart at the time...
What do you think about not running signal handlers for SIGCHLD and
SIGWINCH while zle widgets are running? Postpone them. This already
sort of happens when a signal arrives during recursive-edit.
Roman.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author