8

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 "

2 Answers 2

12

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:

2
  • This is perfect, solved my problem. Thanks a lot for the help! Commented Jan 16, 2012 at 16:42
  • Blair, welcome to Ask Different! If you like an answer to your question please upvote and accept it.
    – nohillside
    Commented Jan 16, 2012 at 18:15
0

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)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .