Skip to content

Instantly share code, notes, and snippets.

@marcroberts
Created October 7, 2016 11:02
Show Gist options
  • Select an option

  • Save marcroberts/a80a6160e9afbe29c29bb7db263c0fd2 to your computer and use it in GitHub Desktop.

Select an option

Save marcroberts/a80a6160e9afbe29c29bb7db263c0fd2 to your computer and use it in GitHub Desktop.
something for watching files in the current directory
#!/usr/local/bin/ruby
require 'rubygems'
require 'inotify'
i = Inotify.new
last_events = {}
watcher = Thread.new do
i.each_event do |ev|
last_events[ev.name] = Time.now.to_i
end
end
mover = Thread.new do
while true do
now = Time.now.to_i
last_events.each do |k, v|
if ( now - v) > 10
print "moving #{k}"
last_events.delete k
end
end
sleep 1
end
end
i.add_watch('.', Inotify::CLOSE_WRITE)
watcher.join
mover.join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment