Sha256: 7962ba6e911bd643c3fbd3f415052505da65fde5d5a4631adb6ec8841c71ec9b

Contents?: true

Size: 665 Bytes

Versions: 22

Compression:

Stored size: 665 Bytes

Contents

#!/usr/bin/env ruby

def execute(*args)
  cmd = args.map(&:inspect) * ' '
  puts "Executing: #{cmd}"
  IO.popen(cmd, 'r') do |io|
    io.each { |l| puts l }
  end
end

argv = ARGV.dup
filename = argv.shift or fail "require a filename as first argument"
argv.empty? and argv << 'true'
argv.map! { |a| a == '%f' ? filename : a }
warn "Observing #{filename.inspect} for changes now and execute #{argv.inspect}."
old_mtime = nil
loop do
  begin
    mtime = File.mtime(filename)
    if old_mtime.nil? || mtime > old_mtime
      execute(*argv)
    else
      sleep 0.1
    end
  rescue Interrupt
    exit 1
  rescue Errno::ENOENT
  ensure
    old_mtime = mtime
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
utils-0.60.1 bin/on_change
utils-0.60.0 bin/on_change
utils-0.59.2 bin/on_change
utils-0.59.1 bin/on_change
utils-0.59.0 bin/on_change
utils-0.58.0 bin/on_change
utils-0.57.1 bin/on_change
utils-0.57.0 bin/on_change
utils-0.56.1 bin/on_change
utils-0.56.0 bin/on_change
utils-0.55.0 bin/on_change
utils-0.54.1 bin/on_change
utils-0.54.0 bin/on_change
utils-0.53.1 bin/on_change
utils-0.53.0 bin/on_change
utils-0.52.1 bin/on_change
utils-0.52.0 bin/on_change
utils-0.51.1 bin/on_change
utils-0.51.0 bin/on_change
utils-0.50.0 bin/on_change