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