Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I am used from Linux to have a colored prompt in my shells and also want to implement that in my OS X Terminal.app. The Terminal reacts differently though. If I use my normal PS1 code the right side of any line will be cut down at a strange point (surely not the right end of the Terminal window). And also the next line will not show on the next line but on the same line.

expected reaction:

erik2:~[06:46 am]$ expectedexpectedexpectedexpectedexpectedexpectedexpect
edexpected_

real reaction:

ectedexpected_am]$ expectedexpectedexpectedexpectedexp

Is that normal for Terminal? Is there an alternative? Did I just code something wrong? Have a look at my PS1 code:

export PS1="\033[0;34m\u:\W\e[0;32m[\@]\e[m\033[0;34m$\033[m "
share|improve this question
add comment

1 Answer 1

up vote 4 down vote accepted

You need to escape the non-printing parts of the prompt by surrounding them with \[…\].

export PS1="\[\033[0;34m\]\u:\W\[\e[0;32m\][\@]\[\e[m\033[0;34m$\033[m\] "

Otherwise, readline gets confused about the remaining space on the command line.

share|improve this answer
add comment

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.