I've the following PS1 prompt:

export PS1="\e[1m\e[38;5;198m\u\e[0m @ \e[1m\e[38;5;208m\h\e[0m : \e[1m\w\e[0m\e[38;5;226m\$(parse_git_branch)\e[0m \e[1m>>>\e[0m "

what happens is that when typing and it reaches halfway through the terminal, it will send the cursor at the beginning of the line and overwrite itself like:

rossid @ HOST : /Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents >>>

oussid @ HOST : /Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents >>>  this is just a test to show what happens nothing seri 

(the rest of the string serious replaces the beginning)

Any idea why? (I'm using osx standard terminal and IntelliJ terminal... all do the same)


You have to enclose all the non printable escape sequences between \[ and \]. For example:

  PS1="\[\e[1m\]\[\e[38;5;198m\]\u\[\e[0m\] @ "

[Shows only part of your prompt. Do the same for rest.]

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.