Skip to content

Instantly share code, notes, and snippets.

@DannyBen
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DannyBen/868952bb0879fb6b990c to your computer and use it in GitHub Desktop.
Save DannyBen/868952bb0879fb6b990c to your computer and use it in GitHub Desktop.
Ruby Filewatcher Interrupt Bug
# See https://github.com/thomasfl/filewatcher/issues/24
$ gem install filewatcher -v0.4.0
$ gem uninstall filewatcher -v0.5.0
$ rvm list
$ ruby -v
$ gem list filewatcher
$ ./test.rb
$ gem install filewatcher
$ gem list filewatcher
$ ./test.rb
$ gem uninstall filewatcher -v0.5.0
#!/usr/bin/env ruby
# With 0.4.0, Ctrl+C is exiting properly. With 0.5.0 it shows
# stack trace
# trap("SIGINT") { puts "\033[2K\rGoodbye"; exit } # claener
trap("SIGINT") { puts "\nGoodbye"; exit }
puts "Watching files..."
fork { exec "filewatcher 'test.rb' 'echo changed'" }
# In real life this is exec'ing Shopify's "theme watch" command
# I copied the bare minimum code from it to the theme.rb file
# See https://github.com/Shopify/shopify_theme/search?utf8=%E2%9C%93&q=watcher
puts "Watching theme..."
fork { exec "./theme.rb" }
Process.waitall
#!/usr/bin/env ruby
require 'filewatcher'
def watcher
FileWatcher.new(Dir.pwd).watch() do |filename, event|
yield(filename, event)
end
end
watcher do |filename, event|
puts "changed #{filename}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment