help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: realine messup with dynamic PS1


From: Chet Ramey
Subject: Re: realine messup with dynamic PS1
Date: Thu, 6 Aug 2026 11:22:56 -0400
User-agent: Mozilla Thunderbird

On 8/5/26 2:51 PM, Christoph Anton Mitterer wrote:

Now as I you can see, the PS1 does itself has dynamic content in the
command substitutions, which produce escape sequences, guarded by the
usual \[ \].

LLM claimed readline would simply not consider these from dynamic
content... but at least most of the time it does seem to work.

This time, the LLM is correct. There are two stages of prompt expansion:
first the expansion of backslash escapes, then word expansions.

"After the string is decoded, it is ex-
panded via parameter expansion, command substitution, arithmetic expansion,
and quote removal, subject to the value of the promptvars shell option (see
the description of the shopt command under SHELL BUILTIN COMMANDS below)."

So the \[ and \] produced by command substitution are not expanded into
the special characters readline requires.

If you want to make this work, you have to expand to the \001 and \002
characters readline interprets, as described in the readline manual:

"Applications may indicate that the prompt contains characters that take
up no physical screen space when displayed by bracketing a sequence of
such characters with the special markers @code{RL_PROMPT_START_IGNORE}
and @code{RL_PROMPT_END_IGNORE} (declared in @file{readline.h} as
@samp{\001} and @samp{\002}, respectively)."

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]