From: Stephane Chazelas <stephane@chazelas.org>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: [PATCH][doc] clarify order of backslash and prompt expansion in print -P
Date: Fri, 28 Jul 2023 10:47:48 +0100 [thread overview]
Message-ID: <20230728094748.vmnnatnyxo7rs2v7@chazelas.org> (raw)
Also remind that you don't need to escape the backslashes if
using print -rP as I've seem people going through all the
trouble of doing that escaping when they could just have use -r.
diff --git a/Doc/Zsh/prompt.yo b/Doc/Zsh/prompt.yo
index 909012c8e..5b31bcd6c 100644
--- a/Doc/Zsh/prompt.yo
+++ b/Doc/Zsh/prompt.yo
@@ -3,8 +3,11 @@ chapter(Prompt Expansion)
sect(Expansion of Prompt Sequences)
cindex(prompt expansion)
cindex(expansion, prompt)
-Prompt sequences undergo a special form of expansion. This type of expansion
-is also available using the tt(-P) option to the tt(print) builtin.
+Prompt sequences undergo a special form of expansion. This type of
+expansion is also available using the tt(-P) option to the tt(print)
+builtin, performed there em(after) backslash expansion unless used in
+combination with the tt(-r) option to disable the latter or tt(-f) to
+specify a format string.
pindex(PROMPT_SUBST, use of)
If the tt(PROMPT_SUBST) option is set, the prompt string is first subjected to
@@ -358,10 +361,12 @@ For example, if the current directory is `tt(/home/pike)',
the prompt `tt(%8<..<%/)' will expand to `tt(..e/pike)'.
In this string, the terminating character (`tt(<)', `tt(>)' or `tt(])'),
or in fact any character, may be quoted by a preceding `tt(\)'; note
-when using tt(print -P), however, that this must be doubled as the
-string is also subject to standard tt(print) processing, in addition
-to any backslashes removed by a double quoted string: the worst case
-is therefore `tt(print -P "%<\\\\<<...")'.
+when using tt(print -P) without tt(-r)/tt(-f), however, that this must
+be doubled as the string is also subject to standard tt(print)
+processing, in addition to any backslashes removed by a double quoted
+string: the worst case is therefore `tt(print -P "%<\\\\<<...")' to
+escape the `tt(<)' and achieve the same as `tt(print -rP '%2<\<<...')'
+or `tt(print -Pf '%s\n' '%2<\<<...')'.
If the var(string) is longer than the specified truncation length,
it will appear in full, completely replacing the truncated string.
next reply other threads:[~2023-07-28 9:48 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-28 9:47 Stephane Chazelas [this message]
2023-07-28 22:54 ` Bart Schaefer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230728094748.vmnnatnyxo7rs2v7@chazelas.org \
--to=stephane@chazelas.org \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).