This is because the printing parts of the prompt \u
in
\w
and :
are in escaped square brackets. The brackets are normally placed around non-printing characters to tell bash not to move the cursor for them and thus correctly calculate the size of the prompt. So now the cursor is not being moved correctly for the printing sections.
I recommend you modify the parts of your .bashrc
that set the prompt rather than overriding it... you could uncomment (remove the #
) this line:
#force_color_prompt=yes
and then modify the second line in this snippet:
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
so it says:
PS1='${debian_chroot:+($debian_chroot)}\[\033[00;34m\]\u \[\033[0;37m\]in \[\033[01;32m\][\[\033[0;31m\]\w\[\033[1;32m\]]\[\033[0;37m\]: '
Or if you prefer just put your override at the end of the file:
PS1='\[\033[00;34m\]\u \[\033[0;37m\]in \[\033[01;32m\][\[\033[0;31m\]\w\[\033[1;32m\]]\[\033[0;37m\]: '
This achieves what I think you want for me in Ubuntu 16.04 and doesn't break in the way you describe (which I have also experienced before when playing with my PS1!)