Created
November 11, 2010 06:22
-
-
Save a2ikm/672106 to your computer and use it in GitHub Desktop.
run command automatically when specified file was modified
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
if ARGV.size < 2 | |
puts "Usage: jamie file command" | |
exit(0) | |
end | |
target = ARGV[0] | |
cmd = ARGV[1] | |
last_mtime = File.mtime(target) | |
loop do | |
sleep 1 | |
mtime = File.mtime(target) | |
if mtime > last_mtime | |
puts "The file was modified ..." | |
system(cmd) | |
last_mtime = mtime | |
puts "" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment