Before I installed Lion opening a terminal window placed the cursor at the end of the prompt like so:

Wed Aug 31{shirsch4@Susan-Hirschs-iMac}/projects/perl/perl/lib/Utils--><cursor>

Now when I open a terminal window I get the cursor somewhere in the middle of the prompt like so:

Wed Aug 31{shirsch4@Susan-Hirsch<cursor>-iMac}/projects/perl/perl/lib/Utils-->

Anyone have any idea how I can correct this?


As requested here is my setting for PS1:

  • As always with questions about the command prompt, please post your PS1 value or your code (if any) that sets it so we can see what the prompt is supposed to be. – Chris Page Sep 1 '11 at 0:12
  • PS1 setting posted above. Thanks. – ennuikiller Sep 1 '11 at 2:05

The most common mistake that can cause this is not using square brackets around non-printing characters in your PS1. Any non-printing characters must be enclosed in "\[…\]" to tell bash not to count them when measuring the length of the prompt.

For example, I have this in my ~/.bashrc to make my prompt bold:

PS1='\['$(tput bold)'\]'"$PS1"'\['$(tput sgr0)'\]'

Each escape sequence is enclosed in square brackets. (I'm using tput to generate the codes instead of hard-coding them like a lot of people do. This is more portable and makes reading and maintaining the shell script easier.)

However, the PS1 you posted seems to have correct square brackets. Moreover, I cannot reproduce the problem you're reporting if I set my PS1 the same as yours. (I'm using 10.7.1.)

  • odd .... can it be the terminal preferences setting? – ennuikiller Sep 1 '11 at 2:26
  • 1
    It's highly unlikely that any Terminal preference setting would cause this. (Other than perhaps changing the $TERM value to something that tells Bash or ncurses to not send some command code your prompt is using.) Have you tried using the default Basic settings profile? A more likely culprit is something in your shell startup file(s). Try using Shell > New Command to run bash --noprofile --norc, then set your PS1 at the command prompt and see if it has the same problem. – Chris Page Sep 1 '11 at 2:33

Found the answer here:

In Terminal I had to go to Preferences->Settings->Advanced, and change xterm-color256 to xterm-color!!

  • In general, although switching to xterm-color may serve as a workaround, doing so typically just masks the problem without fixing it. As of Mac OS X Lion 10.7, using xterm-color with Terminal is not recommended. xterm-color represents an older branch of Xterm, but as of Lion, Terminal is more compatible with modern Xterm. This workaround almost certainly just points out that there's something invalid being sent to the terminal, and switching to xterm-color somehow suppresses it. I recommend continuing to investigate to discover the actual source of the problem. – Chris Page Sep 4 '11 at 8:15
  • Using xterm-color disables several desirable behaviors, such as 256 colors, Background Color Erase (BCE), and the modern Xterm codes for switching to/from the alternate screen while preserving the contents. – Chris Page Sep 4 '11 at 8:17
  • As I mentioned in another comment, I cannot reproduce the problem using your PS1 string, on Lion, with TERM=xterm-256color. There's likely something else in one of your shell configuration files interfering with your prompt. Try commenting out lines until the problem goes away to isolate the source. – Chris Page Sep 4 '11 at 8:21
  • Look through your shell configuration files for anything that depends on the value of $TERM. Look for any actual references to $TERM, as well as calls to tput or other programs that may depend on $TERM. – Chris Page Sep 4 '11 at 8:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.