0

I have customised my PS1 bash variable, but when I go through the history it starts getting bugged and doing weird stuff. I've gone several times over it but can't seem to find anything wrong.

\[\e]0;\u@\h: \w\a\]\[\033[01;32m\]\u@\h\[\033[00m\]\[\e[31m\] (production)\[\e[0m:\]\[\033[01;34m\]\w\[\e[m\]$

The moment when, going through the history, starts to behave weirdly, seems to be somehow related with long lines that need wrapping...

Ypsilon
  • 122
  • 1
  • 9
  • Possible duplicate of ["Custom Bash prompt is overwriting itself"](http://stackoverflow.com/questions/19092488/custom-bash-prompt-is-overwriting-itself) and ["Adding ANSI color escape sequences to a bash prompt results in bad cursor position when recalling/editing commands"](http://stackoverflow.com/questions/17432993/adding-ansi-color-escape-sequences-to-a-bash-prompt-results-in-bad-cursor-positi) and probably others. – Gordon Davisson Oct 30 '19 at 22:37
  • I hate the `PS1` environment variable. It would've been so much better if there was a `prompt_handle` function, kind of like the `command_not_found_handle` function. – Sapphire_Brick Dec 17 '20 at 00:53

1 Answers1

3

The problem is in \[\e[0m:\]. Colon : is a printing character, so it should be outside the nonprinting delimiters, i.e. \[\e[0m\]:.

In the future if you have problems with your PS1, try breaking it into chunks and testing each one.

wjandrea
  • 28,235
  • 9
  • 60
  • 81