def start
if windows?
raise "Sorry, Rerun does not work on Windows."
end
if (!@already_running)
taglines = [
"To infinity... and beyond!",
"Charge!",
]
notify "Launched", taglines[rand(taglines.size)]
@already_running = true
else
taglines = [
"Here we go again!",
"Once more unto the breach, dear friends, once more!",
]
notify "Restarted", taglines[rand(taglines.size)]
end
@pid = Kernel.fork do
begin
exec(@run_command)
rescue => e
puts e
exit
end
end
Process.detach(@pid)
Signal.trap("INT") do
stop
exit
end
begin
sleep 2
rescue Interrupt => e
stop
exit
end
unless running?
notify "Launch Failed", "See console for error output"
@already_running = false
end
unless @watcher
watcher_class = mac? ? OSXWatcher : FSWatcher
watcher = watcher_class.new do
restart unless @restarting
end
puts "Watching #{dir}/#{pattern}"
watcher.add_directory(dir, pattern)
watcher.sleep_time = 1
watcher.start
@watcher = watcher
end
end