Skip to content

Instantly share code, notes, and snippets.

@akahn
Created March 6, 2011 17:57
Show Gist options
  • Save akahn/857453 to your computer and use it in GitHub Desktop.
Save akahn/857453 to your computer and use it in GitHub Desktop.
Output git commits by day
require 'optparse'
options = {
:git_dir => ".git",
:me => false
}
OptionParser.new do |opts|
opts.on("-d", "--git-dir DIR", "specify a git dir") do |dir|
options[:git_dir] = dir
end
opts.on("--me") do |dir|
options[:me] = true
end
end.parse!
me = options[:me] ? "--author=#{`git config --get user.email`}" : ""
git_cmd = "git --git-dir=#{options[:git_dir]} --no-pager log --no-merges --date-order --format=format:'%at %h %an %s' #{me}"
def bold(text)
"\033[1m#{text}\033[0m"
end
def normalized(time)
time.strftime("%F")
end
trap(:INT) do
puts
exit
end
r, w = IO.pipe
spawn({}, git_cmd, :out => w)
memo = Time.now + 86_400
r.each do |line|
begin
parts = line.split("\t")
time = Time.at(parts.shift.to_i)
if normalized(time) != normalized(memo)
puts
puts bold(time.strftime("%A, %B %e, %Y"))
memo = time
end
puts "* " + parts.join(" ")
rescue Errno::EPIPE
break
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment