Skip to content

Instantly share code, notes, and snippets.

@brock
Created November 14, 2012 05:35
Show Gist options
  • Save brock/4070482 to your computer and use it in GitHub Desktop.
Save brock/4070482 to your computer and use it in GitHub Desktop.
Git Commit Calendar
require 'date'
require 'colored'
require 'time'
date = Date.today
puts date.strftime("%B %Y").center(20)
puts "Su Mo Tu We Th Fr Sa"
days_in_month = (Date.new(date.year, 12, 31) << (12 - date.month)).day
commits_from_this_month = `git log --format="%aD" --since=1.month`.split("\n")
dates_of_commits = commits_from_this_month.map{|t| Time.parse(t)}
.take_while {|d| d.month == date.month && d.year == date.year}
.map{|d| d.day}
print " " * Date.new(date.year, date.month, 1).wday
(1..days_in_month).each do |d|
curr_date = Date.new(date.year, date.month, d)
print " " if curr_date.day < 10
print "#{curr_date.day} ".send(dates_of_commits.include?(d) ? :green : :red)
print "\n" if curr_date.wday == 6 && curr_date.day != days_in_month
end
puts "\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment