My updated shell prompt

Updated and fixed 04/13: I had been missing escapes, so command scrollback would get screwed for long lines.

Phil Windley asked, so here you are: this is the code in my .bashrc that causes my shell prompt to have different colors dependending on whether the previous command succeeded or failed. It also shows Git branch info if I’m in a directory that is version controlled.

if [ -f ~/.git-prompt.sh ]; then
    source ~/.git-prompt.sh
    export PS1='$(if [[ $? == 0 ]]; then echo "\[\e[32m\]"; else echo "\[\e[31m\]"; fi )\h [\W]$(__git_ps1 "(%s)") \u $ \[\e[0m\]'
fi

Where .git-prompt.sh is the script from here.

Examples, non-git:

host [~] jernst $ true
host [~] jernst $ false
host [~] jernst $ 

In a git directory:

host [ubos-docs](develop) jernst $ true
host [ubos-docs](develop) jernst $ false
host [ubos-docs](develop) jernst $ 

Comments are closed.