Skip to content

Instantly share code, notes, and snippets.

@rummelonp
Last active August 29, 2015 14:05
Show Gist options
  • Save rummelonp/cf8032c41bd6271563ab to your computer and use it in GitHub Desktop.
Save rummelonp/cf8032c41bd6271563ab to your computer and use it in GitHub Desktop.
git で今週の総追加行数/総削除行数を出すサブコマンド http://mitukiii.hatenablog.com/entry/2014/08/14/221805
#!/usr/bin/env ruby
require 'date'
def stats(desc, from, to = from)
command = "git log" <<
" --oneline" <<
" --shortstat" <<
" --no-merges" <<
" --since='#{from.strftime('%Y-%m-%d')} 00:00:00'" <<
" --until='#{to.strftime('%Y-%m-%d')} 23:59:00'"
output = `#{command}`
lines = output.split(/\n/).grep(/files? changed/)
insertions = 0
deletions = 0
lines.each do |line|
words = line.split(' ')
insertions += words[3].to_i
deletions += words[5].to_i
end
puts desc
puts " #{insertions} insertions(+), #{deletions} deletions(-)"
end
stats 'This week', Date.today - 6, Date.today
stats 'Today', Date.today
stats 'Yesterday', Date.today - 1
stats '2 days ago', Date.today - 2
stats '3 days ago', Date.today - 3
stats '4 days ago', Date.today - 4
stats '5 days ago', Date.today - 5
stats '6 days ago', Date.today - 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment