0

So my bash prompt looks like this [parth:~]$ and if I go cd to Desktop, it looks like this [parth:Desktop]$. I only want to see the current directory, next to my username so if I go to a folder, in Desktop, it would replace Desktop with the current directory name.

This is what I have in my ~/.bash_profile to make it look like this: export PS1='[\033[01;32m\]\u\[\033[00m\]:\[\033[01;34m\]\W\[\033[00m\]]\$ '

This PS1 also follows the color highlighting of my terminal theme.

The problem is that when I click the up arrow key a few times (for the previous commands) and then click the down arrow key, the prompt gets messed up. It appends a part of the previous command to my prompt and I have to enter CTRL + C to reset it. Also when my command reaches the end of the line, instead of going to the new line, it wraps around the same line.

How do I fix this?

2 Answers 2

1

You are missing a couple of begin indicators for the non-printing escape sequences.

You should use this:

PS1='[\[\033[01;32m\]\u\[\033[00m\]:\[\[\033[01;34m\]\W\[\033[00m\]]\$ '

And don't export PS1, it is not an environment variable.

Some discussion about that: https://unix.stackexchange.com/questions/247585/to-export-or-not-to-export-bash-ps1-variable

0

As far as I have been able to tell, this is caused by a bug in iTerm2, where actions such as ctrl+a make it act as though the colour-specifying characters in PS1 are treated as though they have a length.

The best solution I have found is to not specify colours in your .bashrc, and instead use triggers to generate the colours.

1
  • iTerm2 would not know or care about the color sequences. It is the shell not knowing that some of the characters in the prompt are non-printing. The OP missed a couiple of sequence starting escapes. Nov 11, 2022 at 19:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .