This little guard allows you to run shell commands when files are altered.
Make sure you have guard installed.
Install the gem with:
gem install guard-shell Or add it to your Gemfile:
gem 'guard-shell' And then add a basic setup to your Guardfile:
guard init shell If you can do something in your shell, or in ruby, you can do it when a file changes with guard-shell. It simply executes the block passed to watch if a change is detected, and if anything is returned from the block it will be printed. For example
guard:shelldowatch/.*/do |m| m[0] + " has changed."endendwill simply print a message telling you a file has been changed when it is changed. This admittedly isn't a very useful example, but you hopefully get the idea. To run everything on start pass :all_on_start to #guard,
guard:shell,:all_on_start=>truedo# ...endThere is also a shortcut for easily creating notifications,
guard:shelldowatch/.*/do |m| nm[0],'File Changed'endend#n takes up to three arguments; the first is the body of the message, here the path of the changed file; the second is the title for the notification; and the third is the image to use. There are three (four counting nil the default) different images that can be specified :success, :pending and :failed.
guard:shelldowatch/(.*)/do |m| nm[0],'Changed'`say -v cello #{m[0]}`endendguard:shell,:all_on_start=>truedowatch/^([^\/]*)\.tex/do |m| `pdflatex -shell-escape #{m[0]}``rm #{m[1]}.log`count=`texcount -inc -nc -1 #{m[0]}`.split('+').firstmsg="Built #{m[1]}.pdf (#{count} words)"nmsg,'LaTeX'"-> #{msg}"endendguard:shelldowatch/.*\.rb$/do |m| ifsystem("ruby -c #{m[0]}")n"#{m[0]} is correct",'Ruby Syntax',:successelsen"#{m[0]} is incorrect",'Ruby Syntax',:failedendendend