Skip to content

Instantly share code, notes, and snippets.

@chasewoodford
Created October 11, 2012 23:03
Show Gist options
  • Save chasewoodford/3876138 to your computer and use it in GitHub Desktop.
Save chasewoodford/3876138 to your computer and use it in GitHub Desktop.
Sass multiple directory watcher ruby
#######
# Watches files for changes and runs a command if anything was changed.
#
# Modified from https://gist.github.com/286060
#
# Example:
# ruby watcher.rb **/*.scss "sass --update sass:compiled"
#######
trap('INT') { exit! }
cmd = ARGV.pop
files = {}
loop do
updated = 0
ARGV.each do |file|
ctime = File.ctime(file).to_i
if ctime != files[file]
files[file] = ctime
updated += 1
end
end
if updated > 0
puts "Detected #{updated} changed files!"
puts "# #{cmd}"
system(cmd)
puts "Done!"
trap('INT') { exit! }
end
sleep 5
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment