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

[PATCH] promptinit: Use print -rP in preview



Attached (sorry, GMail) please find a one-character patch to fix a
prompt-previewing corner case in promptinit's default/fallback
prompt_preview_theme function.

This chang was wholly inspired by the documentation patch Stephane
Chazelas submitted some time ago:
https://www.zsh.org/mla/workers/2023/msg00726.html

(A patch, I notice, which was never merged. It does seem like SOME
form of documentation update along those lines would benefit the
documentation. The information about 'print -rP' definitely helped me
squash a bug I was beginning to think was unsolvable. It apparently
escaped the notice of the print_preview_theme function's author as
well.)

The adam2 prompt is seemingly alone in triggering this bug, at least
for now, because it contains an escaped character (a backtick) in the
ascii-art version of its $PS1 string. Due to the escaped character,
'prompt -p adam2' (a request to preview the theme) will succeed, but
not without printing an error message between the theme name and the
actual preview: "prompt_preview_theme:22: parse error". Line 22 of the
function is the 'print -P' that attempts to display the theme's value
for $PS1, and would require the backslash be doubled to avoid the
error.

By switching to 'print -rP', the adam2 theme (and all themes) can be
previewed directly from their unaltered $PS1 value by the
prompt_preview_theme function.
From de8cc6054f3bb78d149ad37675068e2538eefc3b Mon Sep 17 00:00:00 2001
From: "FeRD (Frank Dana)" <ferdnyc@xxxxxxxxx>
Date: Tue, 25 Mar 2025 00:04:55 -0400
Subject: [PATCH] promptinit: Use print -rP in preview

Prevents the backslash in the (default) ASCII mode of 'adam2' from
being misparsed during preview, leading to 'prompt -p adam2'
printing an error between the 'adam2 theme:' header and the
actual preview:

prompt_preview_theme:22: parse error
---
 Functions/Prompts/promptinit | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Functions/Prompts/promptinit b/Functions/Prompts/promptinit
index 0c06699e8..7383c6c68 100644
--- a/Functions/Prompts/promptinit
+++ b/Functions/Prompts/promptinit
@@ -246,7 +246,7 @@ prompt_preview_theme () {
   # while the ZLE is not active.
 
   [[ -o promptcr ]] && print -n $'\r'
-  :; print -P -- "${PS1}command arg1 arg2 ... argn"
+  :; print -rP -- "${PS1}command arg1 arg2 ... argn"
 
   [[ -n ${preexec_functions[(r)prompt_${1}_preexec]} ]] &&
       prompt_${1}_preexec
-- 
2.49.0



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