Skip to content

Instantly share code, notes, and snippets.

@peterc
Created January 25, 2010 17:45
Show Gist options
  • Save peterc/286060 to your computer and use it in GitHub Desktop.
Save peterc/286060 to your computer and use it in GitHub Desktop.
watches files and runs a command when they change
#!/usr/bin/ruby
#
# wad - watch and run
# watches files and runs a command when they change
#
# usage: wad <files> <command>
#
# example:
# ./wad index.html stylesheets/*.sass "sass stylesheets/main.sass stylesheets/main.css; open -g http://127.0.0.1:8000/"
cmd = ARGV.pop
files = {}
loop do
ARGV.each do |file|
ctime = File.ctime(file).to_i
if ctime != files[file]
files[file] = ctime
puts "# #{cmd}"
`#{cmd}`
end
end
sleep 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment