Skip to content

Instantly share code, notes, and snippets.

@magnars
Created May 6, 2011 19:20
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 magnars/959600 to your computer and use it in GitHub Desktop.
Save magnars/959600 to your computer and use it in GitHub Desktop.
Show time since last commit and branch name in prompt
NORMAL="\033[0m"
BLUE="\033[1;34m"
cyan="\033[0;36m"
yellow="\033[0;33m"
RED="\033[1;31m"
source ~/bin/git-completion.bash # or where your git-completion.bash is installed
function minutes_since_last_commit {
now=`date +%s`
last_commit=`git log --pretty=format:'%at' -1 2> /dev/null`
if [ $last_commit ]; then
seconds_since_last_commit=$((now-last_commit))
minutes_since_last_commit=$((seconds_since_last_commit/60))
echo $minutes_since_last_commit
else
echo "∞"
fi
}
function __find_warning_color {
local g="$(__gitdir)"
if [ -n "$g" ]; then
local MINUTES_SINCE_LAST_COMMIT=`minutes_since_last_commit`
if [ "$MINUTES_SINCE_LAST_COMMIT" == "∞" ]; then
__warning_color=${cyan}
elif [ "$MINUTES_SINCE_LAST_COMMIT" -gt 30 ]; then
__warning_color=${RED}
elif [ "$MINUTES_SINCE_LAST_COMMIT" -gt 10 ]; then
__warning_color=${yellow}
else
__warning_color=${cyan}
fi
fi
}
PROMPT_COMMAND=__find_warning_color
export PS1="\[${BLUE}\]\W\["'$(echo -e "${__warning_color}")'"\]"' $(__git_ps1 "($(minutes_since_last_commit)m|%s) ")'"\[${NORMAL}\]\$ "
@duckyuck
Copy link

duckyuck commented May 6, 2011

Genialt! Takker :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment