I'm in Linux Mint 20.1 Cinnamon, not that it matters this time,
I have trouble with customizing my PS1, or generally Bash prompt to colorize the last char $
(user); #
(root).
Current PS1 code in .bashrc
:
if [ "$color_prompt" = yes ]; then
color_red=$(tput bold)$(tput setaf 1)
color_green=$(tput bold)$(tput setaf 2)
color_reset=$(tput sgr0)
PS1='${debian_chroot:+($debian_chroot)}\u @ \h $PWD $color_green\$$color_reset '
else
PS1='${debian_chroot:+($debian_chroot)}\u @ \h $PWD \$ '
fi
Problem description:
When I launch the terminal (gnome-terminal
), it looks just fine, but if I go up with an arrow key for history, the text gets garbled after about 10+ ups:
I can't explain it, can you? What am I doing wrong?
PS: I am unsure why it is in single quotes, and if I can just change it to double quotes...
Fail #2
Have just tried to "convert" it to double-quoted format, which leads again to troubles when upping history a dozen or more times.
PS1="\u @ \h \[\$PWD\] \[$(tput bold)\]\[$(tput setaf 2)\]\\$\[$(tput sgr0)\] "
Fail #3
I'm starting to give up by now, my last chance was using escape sequences directly like so:
PS1='\u @ \h $PWD \e[1;32m\$ \e[0m'
It garbles my terminal as described before, I'm currently setting it without colors to be able to work.
$PWD
or$(tput bold)
) are not expanded when your bashrc is read but when the PS1 is being displayed. Go back to the single quoted one, the issue isn't caused by the quotes. – terdon Jul 02 '21 at 15:41