blue="\033[38;5;32m\]\033[48;5;256m\]"
purple="\033[38;5;198m\]"
green="\[\033[0;32m\]"
reset="\[\033[0m\]"
export PS1="$purple\u$green\$(__git_ps1)$blue \W $ $reset"
If the colors were set using the simpler format, as for green
, everything would work fine. But if they're set using the more complex format like in blue
and purple
, it would work and look right at first, but if I navigate through some previous commands etc. suddenly the line would jump into a really weird place and the prompt text would be gone.
What's going on here?
Make sure you surround the escape codes with \[
and \]
. Those markers tell bash that these are non-printing characters.
blue="\[\033[38;5;32m\033[48;5;256m\]"
purple="\[\033[38;5;198m\]"