Skip to content

Instantly share code, notes, and snippets.

@dogeared
Created February 6, 2012 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dogeared/1754397 to your computer and use it in GitHub Desktop.
Save dogeared/1754397 to your computer and use it in GitHub Desktop.
function minutes_since_last_commit {
now=`date +%s`
last_commit=`git log --pretty=format:'%at' -1 2> /dev/null`
if [ "$?" -ne "0" ]; then
minutes_since_last_commit=-1
else
seconds_since_last_commit=$((now-last_commit))
minutes_since_last_commit=$((seconds_since_last_commit/60))
fi
echo $minutes_since_last_commit
}
grb_git_prompt() {
local g="$(__gitdir)"
if [ -n "$g" ]; then
local MINUTES_SINCE_LAST_COMMIT=`minutes_since_last_commit`
if [ "$MINUTES_SINCE_LAST_COMMIT" -gt 30 ]; then
local COLOR=${RED}
elif [ "$MINUTES_SINCE_LAST_COMMIT" -gt 10 ]; then
local COLOR=${YELLOW}
else
local COLOR=${GREEN}
fi
local SINCE_LAST_COMMIT="${COLOR}$(minutes_since_last_commit)m${NORMAL}"
# The __git_ps1 function inserts the current git branch where %s is
if [ "$MINUTES_SINCE_LAST_COMMIT" -ge 0 ]; then
local GIT_PROMPT=`__git_ps1 "(%s|${SINCE_LAST_COMMIT})"`
echo " ${GIT_PROMPT}"
fi
fi
}
function prompt_color() {
#PS1="${CLEAR}${GREEN}☺${CLEAR} ${BLUE}\u${CLEAR} ${BRIGHT_RED}jobs:\j${CLEAR}"
PS1="${CLEAR}${GREEN}\`if [ \$? = 0 ]; then echo ☺; else echo ☹; fi\`${CLEAR} ${BLUE}\u${CLEAR} ${BRIGHT_RED}jobs:\j${CLEAR}"
PS1="$PS1 ${VIOLET}\w${CLEAR}$(grb_git_prompt)\n➥${CLEAR} "
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment