On 1/23/22 6:33 PM, Josh Harcombe wrote:

"user-controlled substitutions" was the wrong phrasing I guess, what I
meant was I was wondering if this same sanitization principle should be
applied to other things that could become part of your prompt while being
controlled by someone else, (e.g. potentially the current git branch name)
but since a) `git-check-ref-format` restricts valid branch names anyway and
b) bash should probably only care about the PS1 built in substitutions then
\W and \w are probably the only ones that would need to be sanitized.

If you're running a command substitution to add characters to your prompt
(such as the current git branch name), and you're concerned about those
characters corrupting the display, add something like `| cat -v' to the
command.

Likewise, if you're concerned that this is a problem, you can use something
like '$(echo $PWD | cat -v)' in your prompt instead of \w and solve it today. The word expansion equivalent for \W is similar.

There is a legitimate reason to filter the result of \w and \W (as well as
\s): the non-printing characters in the result can disturb readline's
redisplay.

However, you can't go too far with this. Following this train to its
logical end means that `pwd' and `cd' would have to sanitize their output,
since the same thing can happen.

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

Reply via email to