Last active
December 16, 2015 11:09
-
-
Save matasar/5424961 to your computer and use it in GitHub Desktop.
Futzing with BBEdit and maven output.
This file contains 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
#!/usr/bin/env ruby | |
# encoding: UTF-8 | |
require 'stringio' | |
require 'rubygems' | |
require 'ruby-debug' | |
lines = [] | |
ARGF.each_line do |ea| | |
# strip bash color codes | |
lines << ea.gsub(/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]/, "").chomp | |
puts ea | |
end | |
class Result < Struct.new(:kind, :file, :line, :message) | |
def initialize(string, kind) | |
lines = string.split("\n").map { |ea| ea.sub(/\[#{kind}\] /i, "") } | |
self.kind = kind | |
self.file, self.line, self.message = lines.shift.split(":") | |
self.message << lines.join("") | |
self.message.gsub!(/"/, "'") | |
end | |
def result_kind | |
case self.kind | |
when 'error' | |
'error_kind' | |
when 'warn' | |
'warning_kind' | |
else | |
'note_kind' | |
end | |
end | |
def for_bbedit | |
"{result_kind:#{result_kind}, result_file:\"#{file}\", result_line:#{line}, message:\"#{message}\"}" | |
end | |
end | |
def group(lines, kind) | |
return [] if lines.empty? | |
all = [] | |
output = lines.dup | |
current = StringIO.new | |
current.puts(output.shift) | |
output.each do |ea| | |
if ea.match(/^\[#{kind}\] \//i) | |
all << current.string | |
current = StringIO.new | |
end | |
current.puts(ea) | |
end | |
all << current.string | |
all | |
end | |
errors = lines.grep(/\A\[error\]/i) | |
warnings = lines.grep(/\A\[warn\]/i) | |
results = group(errors, "error").map { |ea| Result.new(ea, "error").for_bbedit } | |
results += group(warnings, "warn").map { |ea| Result.new(ea, "warn").for_bbedit } | |
debugger | |
exit if results.empty? | |
script = "tell application \"BBEdit\" | |
set error_list to { ¬ | |
#{results.join(", ¬\n")}} | |
make new results browser with data error_list ¬ | |
with properties {name:\"Errors\"} | |
activate | |
end tell | |
" | |
pipe = IO.popen("osascript -", "w") | |
pipe.puts(script) | |
pipe.puts('"Opened BBEdit Browser"') | |
pipe.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment