Weird cmd behaviour after prompt change

by pkaramol   Last Updated April 25, 2017 10:02 AM

I want my prompt to display:

a) current (absolute) working directory, colored in green and

b) in a NEW line, the dollar sign and an empty space.

I am using this line in .profile

export PS1='\e[0;32m$(pwd)\n\e[m$ '

So when in e.g. Desktop, my prompt looks like this:enter image description here

However, sometimes when hitting the up arrow to re-run previous commands, at the start of the prompt a random char sequence appear that does not seem to go away unless I hit enter

e.g.

enter image description here

I have never hit a cd cd Desktop command

The weirdest part is that backspace won't even delete the first one of the two cd commands above!

Any suggestions?



Answers 1


You must make sure the non-printing characters in the prompt are in escaped square brackets, otherwise bash cannot calculate the size of the prompt correctly. I think I have fixed it for you:

PS1='\[\e[0;32m\]$(pwd)\n\[\e[m\]$ '
Zanna
Zanna
April 25, 2017 10:01 AM

Related Questions


How to run .profile from .bashrc file?

Updated May 08, 2017 16:02 PM

"export PS1=" for customizing shell prompting

Updated December 07, 2017 11:02 AM

problem setting up bash_profile

Updated February 20, 2017 10:02 AM


Prepend current git branch in terminal

Updated October 31, 2017 04:02 AM