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

Re: Prompt expansion on signals

On Mon, Nov 29, 2021 at 12:36 PM Roman Perepelitsa
<roman.perepelitsa@xxxxxxxxx> wrote:
> I'm attaching a patch that implements it. Also
> available here:
> https://github.com/romkatv/zsh/commit/cdcb141c880799847f2b068fef5d097736d484d6

This works rather badly when a signal arrives during a long-running
widget like history-incremental-search-backward. Given that my patch
delays only zleredisplay but not "job done" messages, we end up in a
sorry state of having no prompt. Moreover, the next typed character
triggers zleredisplay that may cause prompt reexpansion with wrong

Maybe the "job done" message should also be delayed? That would
probably be OK in practice but I'm not sure. And what about WINCH if
it arrives during history-incremental-search-backward? With my patch
it won't be processed until the widget is done. Doesn't seem ideal.

Maybe a different approach? Perhaps a new zle hook -- something like
zle-prompt-pre-expand -- that zle would invoke every time before
expanding prompt. The name of the prompt would be passed as an
argument ("PS1", "RPS1", etc.). The hook could set REPLY scalar (which
would be initially unset) to an alternative prompt value; it could
also set reply array (also initially unset) to the list of options
that zle must apply on top of the current options before expanding
prompt (alternatively, the hook itself could change options if zle
would guarantee that these changes will be reverted after prompt is
expanded). People who now set PS1 in precmd will be able to do that in
zle-prompt-pre-expand. It will allow their prompt-building code to
react to changes in TTY dimensions and background jobs. It would
simplify my zsh theme's implementation by quite a bit.


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