Skip to content

Instantly share code, notes, and snippets.

@dreamr
Created July 20, 2011 00:35
Show Gist options
  • Save dreamr/1094088 to your computer and use it in GitHub Desktop.
Save dreamr/1094088 to your computer and use it in GitHub Desktop.
# Prompt Setup
function minutes_since_last_commit {
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))
echo $minutes_since_last_commit
}
git_prompt() {
local g="$(__gitdir)"
if [ -n "$g" ]; then
if git diff --quiet 2>/dev/null >&2; then
local COLOR=${txtgrn}
local GIT_PROMPT=`__git_ps1 "|%s: --|"`
echo ${GIT_PROMPT}
else
local MINUTES_SINCE_LAST_COMMIT=`minutes_since_last_commit`
if [ "$MINUTES_SINCE_LAST_COMMIT" -gt 30 ]; then
local COLOR=${txtred}
elif [ "$MINUTES_SINCE_LAST_COMMIT" -gt 10 ]; then
local COLOR=${txtylw}
else
local COLOR=${txtgrn}
fi
local SINCE_LAST_COMMIT="${COLOR}$(minutes_since_last_commit)m${txtrst}"
# The __git_ps1 function inserts the current git branch where %s is
local GIT_PROMPT=`__git_ps1 "|%s: ${SINCE_LAST_COMMIT}|"`
echo ${GIT_PROMPT}
fi
fi
}
PROMPT_COMMAND='PS1="\n${bldblu}\w${txtrst} $(git_prompt) $ ${txtrst}"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment