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.

It's hard to describe the behavior, but here's a short clip:

http://www.youtube.com/watch?v=9KqHBA94FPI

Basically, when entering multi-line commands, at the end of the first line, the insertion block goes back to the start of the first line, writes over the first line, then continues like normal on to the second, third, etc. lines. When deleting, it allows me to delete the whole command, plus the blank spaces on the line above the command (I have it setup so commands get inserted after a line containing user@host/Directory information. It then even allows me to delete the last part of the Directory and host I described above. Sorry I'm terrible at explaining this, the video will do a better job.

Here is the contents of my .bash_profile:

export PS1="\e[31m\u\e[0m@\e[34m\h\e[33m\w\n \$ \e[0m "
share|improve this question

2 Answers 2

You should surround your non-printing characters (in this case, your ANSI escape sequences) with bash escape sequences: \[ and \]. That way bash will know the enclosed characters are not visible, ie. they do not take space, ie. they should not be included in the word-length calculation used by the line-wrapper.

in other words change your PS1 definition:

export PS1="\e[31m\u\e[0m@\e[34m\h\e[33m\w\n \$ \e[0m "

… to:

export PS1="\[\e[31m\]\u\[\e[0m\]@\[\e[34m\]\h\[\e[33m\]\w\n \$ \[\e[0m\] "

And here's the same PS1 value, for human–reading only, with perhaps improved readability (ANSI-escapes in the lower row, bash escapes in the middle and printing characters in the upper row.)

          \u          @          \h          \w\n \$
\[      \]  \[     \] \[      \]  \[      \]        \[     \] 
  \e[31m      \e[0m     \e[34m      \e[33m            \e[0m    

Further reading:

share|improve this answer
    
This is perfect, solved my problem. Thanks a lot for the help! –  Blair Beckwith Jan 16 '12 at 16:42
    
Blair, welcome to Ask Different! If you like an answer to your question please upvote and accept it. –  patrix Jan 16 '12 at 18:15

I everyone,

I had similar problems and I found a solution just by changing my PS1 variable from the original one to a very simple one, just my nam actually : export PS1=Alex

Now my terminal doesn't have any strange behavior anymore.

Hope it gonna help.

Alex (on Mac Lion 10.8)

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.