Skip to content

Instantly share code, notes, and snippets.

@markjlorenz
Created June 25, 2013 20:29
Show Gist options
  • Save markjlorenz/5862065 to your computer and use it in GitHub Desktop.
Save markjlorenz/5862065 to your computer and use it in GitHub Desktop.
Colored BASH prompt, tells you how long it's been since your last commit and the current branch
function minutes_since_last_commit {
Color_Off="\033[0m"
Red="\033[0;31m"
Green="\033[0;32m"
Yellow="\033[0;33m"
git branch &>/dev/null
if [ $? -eq 0 ]; then
now=`date +%s`
last_commit=`git log --pretty=format:'%at' -1`
seconds_since_last_commit=$((now-last_commit))
minutes_since_last_commit=$((seconds_since_last_commit/60))
if [ $minutes_since_last_commit -gt 30 ]; then
echo "$Red${minutes_since_last_commit}m$Color_Off"
elif [ $minutes_since_last_commit -gt 10 ]; then
echo "$Yellow${minutes_since_last_commit}m$Color_Off"
else
echo "$Green${minutes_since_last_commit}m$Color_Off"
fi
fi
}
source ~/.git-completion.bash
source ~/.git-prompt.sh
export GIT_PS1_SHOWDIRTYSTATE=true
export GIT_PS1_SHOWUNTRACKEDFILES=true
export GIT_PS1_SHOWCOLORHINTS=true
export PS1='\u@\h:\W$(__git_ps1 "(%s|`minutes_since_last_commit`)") → '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment