#!/usr/bin/ruby # simple inotify script to watch what happens in a directory # usage: watch [] # (c) 2008 Yoann Guillot # License: WTFPLv2 require "inotify" dstdir = ARGV.shift || '.' mask = ARGV.shift evts = Inotify.constants.inject({}) { |h, cst| v = Inotify.const_get(cst) h[v] = cst if v.kind_of? Integer h } last = nil i = Inotify.new i.add_watch(dstdir, Inotify::ALL_EVENTS) i.each_event { |ev| next if ev.mask & 0x4000_0000 > 0 m = ev.mask & ~0x4000_0000 next if mask and evts[m] !~ /#{mask}/i ev = "\r#{evts[m] || ('%016b' % m)}".ljust(16) + ev.name.inspect if last == ev if $stdout.tty? print '.' $stdout.flush end else puts ev last = ev end }