Skip to content

Instantly share code, notes, and snippets.

@lmullen
Last active November 11, 2015 10:37
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save lmullen/117597e452ed73b4e157 to your computer and use it in GitHub Desktop.
Word count history

A quick and dirty script to check out each commit of a writing project and find the word count of each Markdown file at that point in time. You might want to use this on a clone of your writing repository. NO WARRANTY EXPRESS OR IMPLIED.

#!/usr/bin/env ruby
require "git"
require "csv"
data = []
repo = Git.open(Dir.pwd)
repo.log(10000).each do |commit|
repo.checkout(commit)
date = commit.date
message = commit.message
holder = []
wc = `wc -w *.md`
wc.split("\n").each {|string| holder.push string.strip.split(" ",2)}
holder.each do |value|
value.push date
value.push message
data.push value
end
end
repo.checkout("master")
CSV.open("wordcounts.csv", "wb") do |csv|
csv << ["word_count", "file", "date_time", "commit_message"]
data.each do |row|
csv << row
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment