lib/rerun.rb in rerun-0.2 vs lib/rerun.rb in rerun-0.2.1

- old
+ new

@@ -12,37 +12,41 @@ def initialize(run_command, options = {}) @run_command, @options = run_command, options end def restart + @restarting = true stop start + @restarting = false end def start if (!@already_running) taglines = [ "To infinity... and beyond!", "Charge!", ] - notify "Launching", taglines[rand(taglines.size)] + 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 "Restarting", taglines[rand(taglines.size)] + notify "Restarted", taglines[rand(taglines.size)] end @pid = Kernel.fork do - Signal.trap("HUP") { stop; exit } + # Signal.trap("INT") { exit } exec(@run_command) end - Process.detach(@pid) + Signal.trap("INT") { stop; exit } + # Process.detach(@pid) + begin sleep 2 rescue Interrupt => e # in case someone hits control-C immediately stop @@ -52,22 +56,29 @@ unless running? notify "Launch Failed", "See console for error output" @already_running = false end - watcher_class = osx? ? OSXWatcher : FSWatcher - # watcher_class = FSWatcher + unless @watcher + watcher_class = osx? ? OSXWatcher : FSWatcher + # watcher_class = FSWatcher - watcher = watcher_class.new do - restart + watcher = watcher_class.new do + restart unless @restarting + end + watcher.add_directory(".", "**/*.rb") + watcher.sleep_time = 1 + watcher.start + + @watcher = watcher end - watcher.add_directory(".", "**/*.rb") - watcher.sleep_time = 1 - watcher.start - watcher.join end + + def join + @watcher.join + end def running? signal(0) end @@ -77,15 +88,15 @@ rescue false end def stop - if @pid && @pid != 0 - notify "Stopping" + if @pid && (@pid != 0) + notify "Stopped", "All good things must come to an end." unless @restarting signal("KILL") && Process.wait(@pid) end - rescue + rescue => e false end def git_head_changed? old_git_head = @git_head @@ -99,11 +110,10 @@ end def notify(title, body) growl title, body if has_growl? puts - puts "#{Time.now.strftime("%T")} - #{app_name} #{title}: #{body}" - puts + puts "#{Time.now.strftime("%T")} - #{app_name} #{title}" end end end