1 Reply Latest reply: Apr 16, 2008 6:55 PM by MalcolmDwyer
MalcolmDwyer Level 1 Level 1 (10 points)
I understand how to change the prompt in Terminal.app as described here:


Looking elsewhere I've seen how to include different colors in the prompt:
My prompt without color:
PS1="\h(\w) \$ "
and with color:
PS1="\e[1;36m\h\e[33m(\w) \$\e[0m "

That's hostname in cyan, followed by the path in yellow, then the $, then back to default color for whatever gets typed.

The problem is that whenever I include these escape characters for colored text, the line wrap no longer works properly in Terminal.app. Specifically, when the command extends past the end of the line, the terminal doesn't scroll to the next line... it just wraps back to the beginning of the same line (erasing it in the process). Backspacing to before the wrap then seems to try to undo the linefeed it never got, so I end up one line above where I started.

Also, when using up-arrow to go back into history if there are any of these long lines, it seems to get confused about where it should start writing the command... as though they are being pushed forward on the line by those escaped characters (that shouldn't add any length to the line).

The program logic is fine... a given series of keystrokes always does the correct thing. It is just not being displayed correctly.

I've tried a few different ways of including the escape character, but any that work and give me colors, also cause this wrapping problem.

A quick test:
put the following into your ~/.bash_profile:
export PS1="\e[1;36m\h\e[33m(\w) \$\e[0m "

Open a new terminal window (you should see the cyan and yellow prompt). Then just hold down the letter 'a'. You should see it get screwed up when the line wraps.

Compare the result with
export PS1="\h(\w) \$ "

I get the same result in both Terminal.app and the xterm included with X11 on apple. However, the prompt works fine for me on cygwin, and any number of terminals on linux.

Looks like a Terminal bug, but I'd be happy to hear of a workaround. I find having the color prompt hugely increases readability... particularly when you have to scroll back through a bunch of error messages on a build. It's always easy to spot where you started the last command.

I've had this problem from 10.4.? to 10.5.2.


Mac OS X (10.5.2), Terminal.app