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.31.0 bin/on_change
utils-0.30.2 bin/on_change
utils-0.30.1 bin/on_change
utils-0.30.0 bin/on_change
utils-0.29.0 bin/on_change
utils-0.28.0 bin/on_change
utils-0.27.0 bin/on_change
utils-0.26.1 bin/on_change
utils-0.26.0 bin/on_change
utils-0.25.0 bin/on_change
utils-0.24.2 bin/on_change
utils-0.24.1 bin/on_change
utils-0.24.0 bin/on_change
utils-0.23.3 bin/on_change
utils-0.23.1 bin/on_change
utils-0.23.0 bin/on_change
utils-0.22.1 bin/on_change
utils-0.22.0 bin/on_change
utils-0.21.2 bin/on_change
utils-0.21.1 bin/on_change