Skip to content

Instantly share code, notes, and snippets.

@oponder
Created June 23, 2011 19:36
Show Gist options
  • Save oponder/1043432 to your computer and use it in GitHub Desktop.
Save oponder/1043432 to your computer and use it in GitHub Desktop.
Show git branch and time since last commit in a bash prompt
# Super messy and hacked together from what I saw at http://asemanfar.com/Current-Git-Branch-in-Bash-Prompt, but then with time since last commit smooshed in
export PS1="\[\033[38m\]\u\[\033[01;34m\]:\W \[\033[31m\]\`ruby -e \"git_status = (%x{git status 2> /dev/null}); last_commit = (%x{git log --pretty=format:'%at' -1 2> /dev/null}).gsub(/^\* (.+)$/, '(\1) '); seconds = Time.now.to_f - last_commit.to_f; minutes = seconds.to_f / 60; ((seconds > 60*60*2) ? (time_since_commit = ('+2h')) : (time_since_commit = minutes.to_i.to_s + 'm') if (git_status != ''));print (%x{git branch 2> /dev/null}.split(%r{\n}).grep(/^\*/).first || '').gsub(/^\* (.+)$/, '(' + time_since_commit.to_s + '|\1) ')\"\`\[\033[37m\]$\[\033[00m\] "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment