OS X Terminal text stacking on top of itself

Daryn picture Daryn · Aug 6, 2012 · Viewed 18k times · Source

I'm encountering a strange issue in the Terminal app in Mac OS X Lion. When I enter in a long line of text that should wrap to the next line when it reaches the edge of the Terminal window, it continues to type on top of the text from the line above it.

Here are some screenshots to help illustrate the issue:

Before my text reaches the window edge:

before

After the text reaches the window edge:

after

I've also supplied screenshots of my text and window settings in case those might be helpful.

Text settings:

text

Window settings:

window

Thanks in advance for any assistance offered. I've had this issue for a while and just never got around to it. It's now really becoming a pain in the ass when I get into things that require big grep commands and long path names.

Answer

hamstergene picture hamstergene · Aug 6, 2012

PS1 environment variable determines what shell's prompt will look like. man bash gives full documentation on it. (There are actually several of them, for different modes).

There are number of files that may be setting it, usually one of ~/.profile, ~/.bashrc, /etc/profile or /etc/bashrc.

If you're going to have color codes or other control sequences inside it, you must wrap them with \[ and \] properly (and NOT wrap normal text), otherwise line editing may become messed up like in your case. I suggest resetting PS1 to the default value then carefully adding coloring back item by item.

For example:

PS1='\[\033[1m\033[32m\]\u@\h \w\[\033[0m\]\$ '
       ^^^^^^^^^^^^^^^            ^^^^^^^

Coloring commands are underlined. Note how they are surrounded with \[ \].