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 $ 

Posted

in

by

Tags:

Comments

6 responses to “My updated shell prompt”

To respond on your own website, enter the URL of your response which should contain a link to this post’s permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post’s URL again. (Find out more about Webmentions.)

Mentions