0

A short while ago I asked this question, on how to customise the bash terminal font colours. The question was answered and I got the colours wanting, using the link provided by a helpful user.

The command I was looking for was:

export PS1="\e[1;34m\u@\H : \e[m\[$(tput sgr0)\]"

Which gives me the following, in the desired colour:

user@host :

However, after using this for a while, I notice that my bash terminal is now pretty buggy when recording and accessing the command history. This thread describes the exact issue I'm having, and the solution being, "use \[...\] around the parts of PS1 that have length 0".

I feel like I've tried everything to do exactly that in my PS1, but the history still remains buggy. Can someone please point out what I'm missing?

devklick
  • 127

1 Answers1

1

These parts of the PS1 have length 0, because they set the formatting (using ANSI escape sequences) but do not produce any other output:

\e[1;34m
\e[m
$(tput sgr0)

Also:

  • You can take out $(tput sgr0) because \e[m does the exact same thing.
  • Put the PS1 in single quotes, so that variables and commands in it are dynamic, not static. (Though it's not important in this situation.)

So you're looking for this command:

export PS1='\[\e[1;34m\]\u@\H : \[\e[m\]'
wjandrea
  • 14,236
  • 4
  • 48
  • 98