Skip to content

Instantly share code, notes, and snippets.

@dorfire
Created November 29, 2013 10:17
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 dorfire/7703870 to your computer and use it in GitHub Desktop.
Save dorfire/7703870 to your computer and use it in GitHub Desktop.
Ruby file watch
#!/usr/bin/env ruby
require 'listen'
path = ARGV[0]
abspath = File.expand_path(path)
file_name = File.basename(path)
file_dir = File.dirname(path)
if File.exists?(path)
then
cmd = ARGV[1] % [path] # e.g. "ftp -u ftp://example.com/file.txt %s"
puts "Listening for changes to '#{file_name}' in '#{file_dir}'"
listener = Listen.to(file_dir) do |modified, added, removed|
if modified.include? abspath
then
puts "Executing `#{cmd}`..."
system(cmd)
end
end
listener.start # non blocking
sleep
else
puts "File does not exist"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment