Skip to content

Instantly share code, notes, and snippets.

@raphaelstolt
Created July 31, 2009 22:08
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save raphaelstolt/159470 to your computer and use it in GitHub Desktop.
stakeout.rb
#!/usr/bin/env ruby -w
if ARGV.size < 2
puts "Usage: stakeout.rb <command> [files to watch]+"
exit 1
end
command = ARGV.shift
files = {}
ARGV.each do |arg|
Dir[arg].each { |file|
files[file] = File.mtime(file)
}
end
loop do
sleep 1
changed_file, last_changed = files.find { |file, last_changed|
File.mtime(file) > last_changed
}
if changed_file
files[changed_file] = File.mtime(changed_file)
puts "=> #{changed_file} changed, running #{command}"
system(command)
puts "=> done"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment