Skip to content

Instantly share code, notes, and snippets.

@benhoskings
Created May 31, 2011 00:47
Show Gist options
  • Save benhoskings/999697 to your computer and use it in GitHub Desktop.
Save benhoskings/999697 to your computer and use it in GitHub Desktop.

See all your work in a given repo over the last couple of weeks, collated by day. Makes filling out timesheets much easier.

To run the script, pass it a git repo as the first argument.

ruby timesheeting_like_a_boss.rb ~/projects/babushka

Here's what I see in babushka:

# 2011-05-25 (Wed)
c1dea1b: Return strings from #which and #cmd_dir.
19d4611: Use #blank? instead of #empty? in #grep

# 2011-05-27 (Fri)
1a8fe18: Accept a block in GitRepo#repo_shell.
bd364d7: Uncache deps when their args are changed.
7fb5010: Added draft #rebasing?
4d56b32: Added GitRepo#git_dir.
8e876e7: Rearranged GitRepo a bit and added section comments.

# 2011-05-28 (Sat)
d07953d: Merged Dep.make into Dep#initialize.

# 2011-05-29 (Sun)
0335f6f: Renamed archive_spec to resource_spec.
1626cfc: Removed prefix support from Resource.
0c64ce7: Avoid failed shell command logging in GitRepo#clean?.
2557385: Bumped the git.installer version to 1.7.5.3.
require 'active_support/all'
earliest = Time.now.at_beginning_of_week - 2.weeks
latest = Time.now.at_end_of_week
commits = Dir.chdir(ARGV.first) {
`git log --pretty=format:"%h, %at, %an, %s" | grep "$(git config user.name)"`
}.strip.split("\n").map {|c|
c.split(/,\s*/, 4).tap {|arr|
arr[1] = Time.at(arr[1].to_i)
}
}.select {|c|
c[1] > earliest and c[1] < latest
}.group_by {|c|
c[1].at_midnight
}
commits.keys.sort.each {|day|
puts "# #{day.strftime("%Y-%m-%d (%a)")}"
commits[day].each {|c| puts "#{c[0]}: #{c[3]}" }
puts ""
}
@yob
Copy link

yob commented May 31, 2011

love it, I've added a copy to my ~/bin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment