0

So I recently decided to change my bash prompt and I have a problem. After pressing up arrow a few times so I don't have to write the command I used like a minute ago the command suddenly breaks the whole prompt and the characters are randomly shattered.

I added this to my bash profile:

export PS1="[\e[32m]\u[\e[m]@[\e[32m]\s[\e[m]-[\e[32m]\W[\e[m] >> "

After pressing the up arrow like two or three times, the characters become totally scrambled like this:

do nano ~/.bash_profile-[]Downloads[] >> source ~/.bash_profile  
pwd                                                      sudo nano 
~/.bash_profile

Guys please help me, it's really annoying. Thanks.

TweeZed
  • 55
  • 1
  • 8
  • You need `\[...\]` around non-printing characters, not `[...]`. That's why you have a bunch of `[]` scattered throughout your prompt. – chepner Mar 26 '19 at 19:28
  • That isn't the problem. I know about the `[]` symbols. The problem is, whenever I press up arrow to list through previous commands the text mixes up and looks like randomly generated text from the characters entered before. – TweeZed Mar 27 '19 at 19:38
  • Yes, because `bash` doesn't know how long your prompt really is, because you *aren't* using the `\[...\]` to properly hide the ANSI escape sequences. – chepner Mar 27 '19 at 20:52
  • Thanks! With ur help I was able to solve it. – TweeZed Apr 02 '19 at 18:34

1 Answers1

0

Already answered in comments. Here is the answer:

You need \[...\] around non-printing characters, not [...]. That's why you have a bunch of [] scattered throughout your prompt.

Thanks

TweeZed
  • 55
  • 1
  • 8