Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I like to use a custom prompt (current path in blue) on my unix machine:

export PS1='\[\e[0;34m\]\w \$\[\e[m\] '

But when I try to use it on Mac's terminal it doesn't work: it fails to detect the end of the prompt and overwrites the prompt when I type commands. This also happens when I'm inputting a long command where it wraps over the same line instead of starting a new line.

I don't understand why this is the case since I use bash on both machines. Any suggestions on how to remedy this?

share|improve this question

migrated from stackoverflow.com Sep 8 '12 at 16:37

This question came from our site for professional and enthusiast programmers.

2 Answers 2

I'm not sure why you are getting different results, but the correct value should be

export PS1='\[\e[0;34m\]\w \$\[\e[m\] '

Non-printing characters should be enclosed in \[ \], so that bash can compute the correct length of the prompt on the screen (for cursor-positioning purposes).

share|improve this answer
    
Yes, export PS1='[\e[0;34m]\w \$[\e[m] ' is the value I'm using. I somehow miscopied it in my question. It doesn't work as I explained above. –  mareks Sep 8 '12 at 15:13
    
It works for me. –  Paul R Sep 8 '12 at 15:16
    
@mareks In your comment above, you again seem to be missing the backslash before the [ and ] that enclose the ANSI escape codes for the colors. \[\e[, not [\e[. –  chepner Sep 8 '12 at 16:37

\[\e[ became [\e[ in the post when it wasn't formatted as code. Sorry about the confusion. I solved the problem by updating bash from 3.0 to 4.2 on my mac.

share|improve this answer

Your Answer

 
discard

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