Skip to content

Instantly share code, notes, and snippets.

@a2ikm
Created November 11, 2010 06:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a2ikm/672106 to your computer and use it in GitHub Desktop.
Save a2ikm/672106 to your computer and use it in GitHub Desktop.
run command automatically when specified file was modified
#!/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