Skip to content

Instantly share code, notes, and snippets.

@beberlei
Forked from proofek/watchr.rb
Last active December 21, 2015 04:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beberlei/6250517 to your computer and use it in GitHub Desktop.
Save beberlei/6250517 to your computer and use it in GitHub Desktop.

Dependency "watchr":

sudo gem install watchr

On Macs:

sudo gem install growl

Uses notify-send on other systems than Mac.

Call "watchr ./watch.rb" in your project

watch('(.*).php') { |m| code_changed(m[0]) }
def code_changed(file)
args = if file.end_with?('Test.php')
file
else
""
end
run "phpunit --colors " + args.to_s
end
def run(cmd)
result = `#{cmd}`
growl result rescue nil
end
def growl(message)
puts(message)
message = message.split("\n").last(3);
growlnotify = `which growlnotify`.chomp
sendnotify = false
if growlnotify.empty?
sendnotify = true
growlnotify = `which notify-send`.chomp
end
title = message.find { |e| /FAILURES/ =~ e } ? "FAILURES" : "PASS"
if title == "FAILURES"
image = "~/.watchr_images/failed.png"
info = /\x1b\[37;41m\x1b\[2K(.*)/.match(message[1])[1]
else
image = "~/.watchr_images/passed.png"
info = /\x1b\[30;42m\x1b\[2K(.*)/.match(message[1])[1]
end
if sendnotify
options = "-i '#{File.expand_path(image)}' '#{title}' '#{info}'"
else
options = "-w -n Watchr --image '#{File.expand_path(image)}' --html '#{title}' -m '#{info}'"
end
system %(#{growlnotify} #{options} &)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment