brock
11/14/2012 - 5:35 AM

Git Commit Calendar

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"