Skip to content

Instantly share code, notes, and snippets.

@ox
Created November 14, 2012 04:54
Show Gist options
  • Select an option

  • Save ox/4070330 to your computer and use it in GitHub Desktop.

Select an option

Save ox/4070330 to your computer and use it in GitHub Desktop.
A commit-based calendar. If a commit was made on a day, that day is green, otherwise red.
require 'date'
require 'time'
require 'colored'
time = Date.today
puts time.strftime("%B %Y").center(20)
puts "Su Mo Tu We Th Fr Sa"
sday = Date.new(time.year, time.month, 1)
days_in_month = (Date.new(time.year, 12, 31) << (12-time.month)).day
commits_from_this_month = `git log --format="%aD" --since=1.month`.split("\n")
dates = commits_from_this_month.map { |n| Time.parse(n) }.take_while do |n|
n.month == time.month and n.year == time.year
end
days = dates.map { |n| n.day }
print " " * sday.wday
(1..days_in_month).each do |n|
print n.to_s.rjust(2).send(days.include?(n) ? :green : :red)
(sday = sday + 1).wday == 0 ? print("\n") : print(" ")
end
puts "\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment