Skip to content

Instantly share code, notes, and snippets.

@maxcal
Forked from appbackr/watch.rb
Created September 30, 2012 18:42
Show Gist options
  • Save maxcal/3808114 to your computer and use it in GitHub Desktop.
Save maxcal/3808114 to your computer and use it in GitHub Desktop.
watchr.rb
$exec = "phpunit"
watch('./(.*).php') { |m| changed(m[0]) }
def changed(file)
run "phpunit"
end
def run(cmd)
result = `#{cmd}`
puts result
# Use terminal-notify
#notify result
growl result
end
def notify(result)
ok = /^(OK.*)$/.match(result)
fail = /(FAILURES!$\n.*$)/.match(result)
msg = ok ? ok : fail
cmd = "terminal-notifier"
cmd = cmd + " -message '#{msg}'"
cmd = cmd + " -title " + "PHPUnit"
system cmd
end
def growl(message)
ok = /^(OK.*)$/.match(message)
fail = /(FAILURES!$\n.*$)/.match(message)
message = ok ? ok : fail
image = "~/#{ok ? 'passed' : 'failed' }.png"
options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}'"
full = %(#{'growlnotify'} #{options} &)
system full
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment