crnixon (owner)

Revisions

  • a02ace crnixon Mon Mar 02 09:28:16 -0800 2009
  • 4b249f crnixon Mon Mar 02 09:27:04 -0800 2009
gist: 72873 Download_button fork
public
Public Clone URL: git://gist.github.com/72873.git
Embed All Files: show embed
rstakeout.rb #
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env ruby
 
# Originally by Mike Clark and Geoffrey Grosenbach.
# From http://www.pragmaticautomation.com/cgi-bin/pragauto.cgi/Monitor/StakingOutFileChanges.rdoc
#
# Runs a user-defined command when files are modified.
#
# Like autotest, but more customizable. This is useful when you want to do
# something other than run tests. For example, generate a PDF book, run
# a single test, or run a legacy Test::Unit suite in an app that also
# has an rSpec suite.
#
# Can use Ruby's Dir[] to get file glob. Quote your args to take advantage of this.
#
# rstakeout 'rake test:recent' **/*.rb
# => Only watches Ruby files one directory down (no quotes)
#
# rstakeout 'rake test:recent' '**/*.rb'
# => Watches all Ruby files in all directories and subdirectories
 
command = ARGV.shift
files = {}
 
ARGV.each do |arg|
  Dir[arg].each { |file|
    files[file] = File.mtime(file)
  }
end
 
puts "Watching #{files.keys.join(', ')}\n\nFiles: #{files.keys.length}"
 
trap('INT') do
  puts "\nQuitting..."
  exit
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}"
    puts `#{command}`
    puts "=> done"
  end
end
 
Text only #
1
rstakeout 'touch tmp/restart.txt' '**/*'