Skip to content

Instantly share code, notes, and snippets.

@lstoll
Created December 15, 2009 00:30
Show Gist options
  • Save lstoll/256597 to your computer and use it in GitHub Desktop.
Save lstoll/256597 to your computer and use it in GitHub Desktop.

Stakeout

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment