Skip to content

Instantly share code, notes, and snippets.

@davidnunez
Forked from ttscoff/gitlogger.rb
Created May 14, 2012 08:01
Archive marked git repositories daily commits to Day One and/or text file
#!/usr/bin/ruby
require 'time'
require 'erb'
filename = "~/.gitlogger"
## File format, One per line
# Repo Name:/path/to/base
dayone = true # log to day one? (true or false)
textlog = "~/Dropbox/nvALT2.2/GitLogger.md" # set to false to disable
entrytext = ""
File.open(File.expand_path(filename),'r') do |infile|
while (line = infile.gets)
name,path = line.strip.split(':')
Dir.chdir(path)
entrytext += %x{git log --pretty=format:"* **[#{name}]** %%%ct%%: %s (%h)%n%n %b%n" --since="yesterday"}.gsub(/%(\d+)%/) { |timestamp|
timestamp.gsub!(/%/,'')
Time.at(timestamp.to_i).strftime("%I:%M %p").gsub(/^0/,'')
}
end
end
entrytext += "\n"
if dayone
uuid = %x{uuidgen}.gsub(/-/,'').strip
datestamp = Time.now.utc.iso8601
starred = false
dayonedir = %x{ls ~/Library/Mobile\\ Documents/|grep dayoneapp}.strip
dayonepath = "~/Library/Mobile\ Documents/#{dayonedir}/Documents/Journal_dayone/entries/"
entry = "## Git Log #{Time.now.strftime("%D")}:\n\n#{entrytext.gsub(/^\s{4}\n/,"").gsub(/\n{3,}/m,"\n\n")}"
template = ERB.new <<-XMLTEMPLATE
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Creation Date</key>
<date><%= datestamp %></date>
<key>Entry Text</key>
<string><%= entry %></string>
<key>Starred</key>
<<%= starred %>/>
<key>UUID</key>
<string><%= uuid %></string>
</dict>
</plist>
XMLTEMPLATE
fh = File.new(File.expand_path(dayonepath+uuid+".doentry"),'w+')
fh.puts template.result(binding)
fh.close
# puts "ENTRY ADDED"
# puts "------------------------"
# puts "Time: " + datestamp
# puts "UUID: " + uuid
# puts "Starred: " + starred.to_s
# puts "Entry: " + entrytext
end
if textlog
entry = "### #{Time.now.strftime("%D")}:\n\n#{entrytext.gsub(/^\s{4}\n/,"").gsub(/\n{3,}/m,"\n\n")}"
open(File.expand_path(textlog), 'a') { |f|
f.puts entry
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment