Wednesday, April 6, 2011

Fixing my Bash Prompt on OSX

I have been having a problem with the bash prompt. When I use the up and down arrows to scroll throw the history buffer, the output of the previous commands would get garbled and not line up. After messing around for 20 minutes I found a solution.

My old prompt:

PS1='\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[0;31m\]$(parse_git_branch_and_add_brackets)\[\033[00m\]\$ '


My new prompt:

PS1='\[\e[01;32m\]\u@\h:\[\e[01;34m\]\w\[\e[0;31m\]$(parse_git_branch_and_add_brackets)\[\e[0m\]$ '


Something about changing the \033 to \e works. Why? I don't know, if you do please comment.