paolodona / scripts

a collection of useful ruby scripts

This URL has Read+Write access

scripts / stakeout
100755 34 lines (24 sloc) 0.512 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env ruby
 
if ARGV.size < 2
puts "Usage: stakeout.rb <command> [files to watch]+"
exit 1
end
 
command = ARGV.shift
files = {}
 
ARGV.each do |arg|
Dir[arg].each { |file|
files[file] = File.mtime(file)
}
end
 
loop do
 
sleep 1
 
changed_file, last_changed = files.find { |file, last_changed|
File.mtime(file) > last_changed
}
 
if changed_file
files[changed_file] = File.mtime(changed_file)
puts "=> #{changed_file} changed, running #{command}"
system(command)
puts "=> done"
end
 
end