This question already has an answer here:

My question is similar, but different to, this question.

I have created a custom PS1 in my .bashrc, as follows:

export PS1="\n$STARTCOLOR\u@\h:\! <\t> \w\n\$ $ENDCOLOR"

Which looks like so (but with color, of course):

tony@home:515 <17:04:52> ~/IdeaProjects/SomeProject
$ gedit ~/.bashrc

I first noticed the issue when linking my project to my remote git repo. I expected the following (not a real repo, of course):

$ git remote add origin https://tony@bitbucket.org/tony/someproject.git

But instead got (note that it even overwrote part of my PS1):

project.gitte add origin https://tony@bitbucket.org/tony/some

The commands still work, even with this visual oddity.

tl;dr When I have long commands that exceed a single line, the second line overwrites the first. Any ideas why?

marked as duplicate by Gilles bash Jul 16 '15 at 22:41

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Already has an answer in the thread you linked to: "Test should not be counted as a visible character and should be included between \[ and \]." – n.st Jul 16 '15 at 21:35

Wrap your colour escape sequences in \[ and \] (like mentioned in the answer to the question you linked to) to mark them as non-printable characters.
That way, bash won't count them towards the prompt length when calculating after how many characters it should move to a new line.

export PS1="\n\[$STARTCOLOR\]\u@\h:\! <\t> \w\n\$ \[$ENDCOLOR\]"

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