Skip to content

Instantly share code, notes, and snippets.

@rf-
Created February 1, 2013 21:40
Show Gist options
  • Save rf-/4694347 to your computer and use it in GitHub Desktop.
Save rf-/4694347 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# grd: micro Guard.
#
# Watch one or more filename patterns and then run the given command every time
# something changes.
#
# Example:
# grd my_model "rspec spec/models/my_model_spec.rb"
require 'listen'
unless ARGV[0] && ARGV[1]
puts 'USAGE: grd pattern1,pattern2,pattern3 "some command"'
exit 1
end
files = ARGV[0].split(',').map { |f| Regexp.new(Regexp.escape(f)) }
Listen.to('.', filter: files) { system ARGV[1] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment