Run it like this:
stakeout.rb "clear && rake throne:push_design:db && curl --silent <url> | jsonpretty" '**/*'
#!/usr/bin/env ruby | |
if ARGV.size < 2 | |
puts "Usage: stakeout.rb <command> [files to watch]+" | |
puts "If you are using a glob, you will probably need to '' it." | |
exit 1 | |
end | |
command = ARGV.shift | |
files = {} | |
ARGV.each do |arg| | |
Dir[arg].each { |file| | |
p file | |
files[file] = File.mtime(file) | |
} | |
end | |
# run at startup | |
system(command) | |
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 |