commit ec4b87b34a5f180b3613abcc7714c6d8ceb36dd3
parent b3c2ffbf9edbbdd6bd6cb1769543c4093f15f835
Author: Kévin Le Gouguec <kevin.legouguec@gmail.com>
Date: Fri, 3 Feb 2023 07:56:09 +0100
Give up on colored PS4
The first mistake here was to forget to wrap console codes with \[…\];
for some reason though after adding those…
export PS4=$(echo -en '\[\e[7m\]+ \[\e[0m\]')
… bash no longer repeats the first character (+) according to the
indirection level, or rather, it repeats an entirely unrelated
character:
$ ( PS4='+ ' ; set -x ; echo $(echo $(echo hi | grep hi)) )
+++ echo hi
+++ grep --color=auto hi
++ echo hi
+ echo hi
hi
$ ( PS4=$(echo -en '\[\e[7m\]+ \[\e[0m\]')
set -x
echo $(echo $(echo hi | grep hi))
) |& hexdump -C
00000000 01 01 01 1b 5b 37 6d 02 2b 20 01 1b 5b 30 6d 02 |....[7m.+ ..[0m.|
^^ ^^ ^^ (echo)
00000010 65 63 68 6f 20 68 69 0a 01 01 01 1b 5b 37 6d 02 |echo hi.....[7m.|
^^ ^^ ^^ (grep)
00000020 2b 20 01 1b 5b 30 6d 02 67 72 65 70 20 2d 2d 63 |+ ..[0m.grep --c|
00000030 6f 6c 6f 72 3d 61 75 74 6f 20 68 69 0a 01 01 1b |olor=auto hi....|
^^ ^^ (echo)
00000040 5b 37 6d 02 2b 20 01 1b 5b 30 6d 02 65 63 68 6f |[7m.+ ..[0m.echo|
00000050 20 68 69 0a 01 1b 5b 37 6d 02 2b 20 01 1b 5b 30 | hi...[7m.+ ..[0|
^^ (echo)
00000060 6d 02 65 63 68 6f 20 68 69 0a 68 69 0a |m.echo hi.hi.|
0000006d
No idea where those ^A characters come from.
While at it, wrap PS2 to avoid line-wrapping shenanigans.
Diffstat:
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/.bash_prompt b/.bash_prompt
@@ -58,11 +58,11 @@ __set-title ()
echo -ne "\E]2;${title}\a"
}
-# In order to know how much space PS1 takes, Bash needs us to delimit
-# non-printing characters with \[ and \].
+# In order to know how much space a prompt takes, Bash needs us to
+# delimit non-printing characters with \[ and \].
__start-nonprinting ()
{
- if [ ${BUILDING_PS1} ]
+ if [ ${BUILDING_PS} ]
then
echo -en '\['
fi
@@ -70,7 +70,7 @@ __start-nonprinting ()
__end-nonprinting ()
{
- if [ ${BUILDING_PS1} ]
+ if [ ${BUILDING_PS} ]
then
echo -en '\]'
fi
@@ -118,11 +118,11 @@ __fontify ()
__set-prompt ()
{
- BUILDING_PS1=t
+ BUILDING_PS=t
PS1="$(__write-context)\n$(__fontify '\$' dim) "
- unset BUILDING_PS1
+ unset BUILDING_PS
}
__current-column ()
@@ -209,9 +209,6 @@ __init-smart ()
{
### Prompts.
- PS2=$(__fontify '… ' dim)
- export PS4=$(__fontify "${PS4}" reverse)
-
if __have-gitprompt
then
. /usr/lib/git-core/git-sh-prompt
@@ -223,6 +220,11 @@ __init-smart ()
PROMPT_COMMAND=__refresh-terminal
+ PS2=$(
+ BUILDING_PS=t
+ __fontify '… ' dim
+ )
+
### Bindings.
bind -f ~/.bash_inputrc