Sha256: eb2472359685764402e94767d56ee2b3be7ff4898440948676e4d21de1947f7c

Contents?: true

Size: 683 Bytes

Versions: 105

Compression:

Stored size: 683 Bytes

Contents

#!/usr/bin/env ruby
# encoding: UTF-8

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

105 entries across 105 versions & 1 rubygems

Version Path
utils-0.48.0 bin/on_change
utils-0.47.0 bin/on_change
utils-0.46.0 bin/on_change
utils-0.45.0 bin/on_change
utils-0.44.0 bin/on_change
utils-0.43.0 bin/on_change
utils-0.42.0 bin/on_change
utils-0.41.0 bin/on_change
utils-0.40.0 bin/on_change
utils-0.39.0 bin/on_change
utils-0.38.0 bin/on_change
utils-0.37.1 bin/on_change
utils-0.37.0 bin/on_change
utils-0.36.0 bin/on_change
utils-0.35.0 bin/on_change
utils-0.34.0 bin/on_change
utils-0.33.1 bin/on_change
utils-0.33.0 bin/on_change
utils-0.32.0 bin/on_change
utils-0.31.1 bin/on_change