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.

I have the following prompt set in my bash_profile:

export PS1='\[\e[1;94m\h:\W \u\e[1;93m\$\e[0m \]'
# default = '\h:\W \u\$ '

Unfortunately, under certain conditions I encounter problems:

  • At a blank prompt, I type a character and then press backspace - the prompt is erased entirely and the cursor goes to the left edge of the terminal instead of simply deleting the character

  • If I use the up and down arrow keys for autocompletion for commands that span multiple lines, only the current line changes but the line above (after the prompt) is left alone

How can I correct my prompt to behave properly in all circumstances as the default one does?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You want the \[ ... \] around the nonprinting parts of the prompts (i.e. the escape sequences), not the entire thing. Since you have them around the entire thing, bash can't figure out how much space on screen the prompt takes up, and will redraw the command in the wrong place. Here's what it should be:

export PS1='\[\e[1;94m\]\h:\W \u\[\e[1;93m\]\$\[\e[0m\] '
share|improve this answer
    
Ahh... makes sense. Thanks so much, this was getting annoying! :) –  Jake Petroules Dec 2 '12 at 4:59

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.