require 'fileutils' module HappyCommit def self.sounds @sounds ||= Dir.glob(File.dirname(__FILE__)+"/../sounds/*.wav") end def self.install if File.exist?(self.hooks_path) FileUtils.mkpath(self.sounds_path) self.sounds.each_with_index do |sound, i| FileUtils.cp(sound, self.sounds_path+"/#{i}.wav") end File.open(self.post_commit_path, "w") do |f| f << %@#!/usr/bin/env ruby sounds = Dir.glob(".git/sounds/*.wav") system("aplay #\{sounds.at(rand(sounds.size))} 2>/dev/null &") @ end FileUtils.chmod(0755, self.post_commit_path) end end protected def self.sounds_path ".git/sounds" end def self.hooks_path ".git/hooks" end def self.post_commit_path "#{self.hooks_path}/post-commit" end end