Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I use the following entry in ~/.bashrc file to colorize the prompt and display current branch of git repository:

PS1='\[\e[1;32m\]\[\u@\h\]\[\e[m\] \[\w\]\[\e[1;1m\]\[$(__git_ps1 " (%s)")\] \[\e[1;1m\]\[$\] \[\e[m\]'

This works almost fine, except when I use bash history (up arrow key few times), the command line becomes 'outdented' (just the first characters of the prompt remains untouched), and the visible is:


when my username is user and the command is command.

share|improve this question

3 Answers 3

\[ and \] should only be used around parts of the command prompt that do not advance the cursor, despite having actual text. if __git_ps1 produces any visible output then this will desynchronize your command line.

share|improve this answer
Just to clarify, it should not be around \u@\h, \w or $ either. – Dennis Williamson Jun 4 '10 at 15:08
up vote 2 down vote accepted

This is the correct version:

GIT_STATUS=$(__git_ps1 " %s")

export PS1
share|improve this answer

Anyone working with this issue, here is the example that worked for me:


export PS1="\033[0;33m[\u@\h]\033[1m\e[m \w \033[36m[>>]\033[0m\e[m "


export PS1='\[\033[0;34m\][\u@\h]\[\033[1m\e[m\] \w \[\033[35m\][>>]\[\033[0m\e[m\] '

Notes all the '\\[\\]' around the colors.

share|improve this answer
Can you explain the difference between the single quotes and the double quotes, as it relates to this prompt? – Stefan Lasiewski Mar 9 '12 at 0:57

Your Answer


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.