Skip to content

Instantly share code, notes, and snippets.

@jowl
Created September 17, 2012 11:48
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jowl/3736877 to your computer and use it in GitHub Desktop.
Save jowl/3736877 to your computer and use it in GitHub Desktop.
Take photo automatically after every git commit. Run `gitshot --enable` in project base dir to enable.
#!/usr/bin/env ruby
require 'fileutils'
APP = __FILE__.split('/').last
pwd = Dir.pwd
if ARGV.include? '--enable'
post_commit = File.join(pwd,'.git/hooks/post-commit')
abort('post commit hook already exist!') if File.exists?(post_commit)
File.open(post_commit,'w') do |file|
file.puts '#!/bin/sh', __FILE__
file.chmod(0755)
end
else
project = pwd.split('/').last
dir = File.join(ENV['HOME'], ".#{APP}", project)
FileUtils.mkdir_p dir
file_name = File.join(dir, "#{Time.now.to_i}.jpg")
system "imagesnap -q #{file_name}"
puts "#{APP} saved your picture to #{file_name}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment