Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have configured a fancy two-line PS1 bash prompt, with server name, time, user name and other useful variables.

PS1="\n\[\033[1;34m\]\342\226\210\342\226\210 \u @ $SERVER_NAME""$BBlue"" \w""$Color_Off  \n\[\033[0;36m\]\342\226\210\342\226\210 \d \t $ \[\033[0;39m\]"

enter image description here

Full Github source here.

The problem is that long lines are often wrapped around themselves, meaning that the new line overlaps the previous one.

The problem is inconsistent: some lines are wrapped correctly, some are not.

Any idea how to fix this?

share|improve this question

3 Answers 3

Found this solution online, which suggested a closing brackets to color variables:

Change this:

Black='\e[0;30m'        # Black
Red='\e[0;31m'          # Red
Green='\e[0;32m'        # Green

to:

Black='\e[0;30m\]'        # Black
Red='\e[0;31m\]'          # Red
Green='\e[0;32m\]'        # Green

I've committed the change - hope it works as expected.

share|improve this answer

Here is my fancy two-line PS1 for bash prompt.

PS1

\[\e[1;32m\]\H\[\e[0m\] :: \[\e[1;30m\]\d\[\e[0m\] \@ :: \[\e[1;33m\]\w\n\[\e[1;34m\]\u $ \[\033[0m\]

So here is what I did. If this was my color:

\e[1;32m

I changed it to:

\[\e[1;32m\]

Essentially you need to enclose it in:

\[$mycolor\]

Checkout this answer.

share|improve this answer
    
+1 Thanks. Oddly enough, it doesn't seem to work on mac. –  Adam Matan Feb 25 '13 at 14:21

My preferred solution to the issue of long lines overlap in bash PS1 is to have a \n at the end of PS1 prompt line(s).

e.g.

enter image description here

If you want all my other stuff - time, user, host, directory and git branch(!) you can use this (mac or linux):

http://unix.stackexchange.com/a/124012/10043

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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