Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

Thanks!

As requested here is my setting for PS1:

/etc/bashrc:PS1="\[\033[01;34m\]\d\[\033[00;36m\]{\u@\h}\[\033[00;35m\]\w\[\033[01;34m\]\[\033[001;34m\]-->"
share|improve this question

migrated from stackoverflow.com Sep 1 '11 at 9:49

This question came from our site for professional and enthusiast programmers.

    
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

2 Answers 2

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.)

share|improve this answer
    
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
up vote 0 down vote accepted

Found the answer here:

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

share|improve this answer
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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