Created
October 11, 2012 23:03
-
-
Save chasewoodford/3876138 to your computer and use it in GitHub Desktop.
Sass multiple directory watcher ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
####### | |
# 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