lib/rerun.rb in rerun-0.2.1 vs lib/rerun.rb in rerun-0.4
- old
+ new
@@ -1,11 +1,11 @@
require "system"
require "watcher"
require "osxwatcher"
require "fswatcher"
-# todo: make this work in non-Mac and non-Unix environments (also Macs without growlnotify)
+# todo: make sure this works in non-Mac environments (also Macs without growlnotify)
module Rerun
class Runner
include System
@@ -18,11 +18,19 @@
stop
start
@restarting = false
end
+ def dir
+ @options[:dir] || "."
+ end
+
def start
+ if windows?
+ raise "Sorry, Rerun does not work on Windows."
+ end
+
if (!@already_running)
taglines = [
"To infinity... and beyond!",
"Charge!",
]
@@ -35,18 +43,25 @@
]
notify "Restarted", taglines[rand(taglines.size)]
end
@pid = Kernel.fork do
- # Signal.trap("INT") { exit }
- exec(@run_command)
+ begin
+ # Signal.trap("INT") { exit }
+ exec(@run_command)
+ rescue => e
+ puts e
+ exit
+ end
end
+ Process.detach(@pid) # so if the child exits, it dies
- Signal.trap("INT") { stop; exit }
+ Signal.trap("INT") do # INT = control-C
+ stop # first stop the child
+ exit
+ end
- # Process.detach(@pid)
-
begin
sleep 2
rescue Interrupt => e
# in case someone hits control-C immediately
stop
@@ -57,20 +72,20 @@
notify "Launch Failed", "See console for error output"
@already_running = false
end
unless @watcher
- watcher_class = osx? ? OSXWatcher : FSWatcher
+ watcher_class = mac? ? OSXWatcher : FSWatcher
# watcher_class = FSWatcher
watcher = watcher_class.new do
restart unless @restarting
end
- watcher.add_directory(".", "**/*.rb")
+ puts "Watching #{dir}"
+ watcher.add_directory(dir, "**/*.rb")
watcher.sleep_time = 1
watcher.start
-
@watcher = watcher
end
end
@@ -108,10 +123,10 @@
git_head_file = File.join(dir, '.git', 'HEAD')
@git_head = File.exists?(git_head_file) && File.read(git_head_file)
end
def notify(title, body)
- growl title, body if has_growl?
+ growl title, body
puts
puts "#{Time.now.strftime("%T")} - #{app_name} #{title}"
end
end