public
Last active

Show a Git status indicator in your shell prompt

  • Download Gist
git-ps1.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13
# git-ps1.sh --- show a git status indicator in your shell prompt
 
# Copy this code into your ~/.bash_profile and customize as needed.
 
function color { echo '\[\e['$1'm\]'; }
 
plain=$(color 0); bold=$(color 1)
red=$(color 31); blue=$(color 34)
 
function git-dirty { [ -n "$(git status --porcelain 2>/dev/null)" ]; }
function git-ps1 { git-dirty && echo -n "*"; }
 
PS1="${bold}${blue}\h${plain}:\w${bold}${red}\$(git-ps1)${plain}\$ "

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.