Terminal Problems OS X 10.6.4

I commonly have long terminal commands and whenever I try to use the command history (by pressing the up-arrow) the text formatting becomes all garbled and the cursor appears in the wrong place. At this point editing the command becomes impossible and the actual position of the cursor is not properly represented on the screen.

If I resize the terminal window to allows the entire command to fit on one line then the formatting gets corrected but sometimes I don't have enough screen real estate to accomplish this. Any ideas?


Solution 1:

Have you customized your shell prompt (e.g. colorization or something like that)? The usual reason that this happens is that you have non-printing characters in your prompt (e.g. color change sequences) and they confuse the shell about how wide the prompt is, and therefore how to wrap the command line.

Assuming you're using bash as your shell, the correct solution is to wrap the nonprinting sequences in \[...\] to let the shell know they're nonprinting. For instance, if you wanted your prompt to be blue (\e[0;34m to turn it blue, \e[m to go back to normal), you'd use:

PS1='\[\e[0;34m\]your prompt text here\[\e[m\]'