Last active
March 5, 2018 21:34
-
-
Save aloiscochard/4698501 to your computer and use it in GitHub Desktop.
QuickSBT - Launch SBT with support for generating /tmp/sbt.quickfix file for Vim
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 bash | |
############ | |
# QuickSBT # | |
############ | |
# Launch SBT with support for generating /tmp/sbt.quickfix file for Vim | |
# http://github.com/aloiscochard / https://gist.github.com/4698501 | |
# Error format for SBT, and shortcut to open SBT quickfix file : | |
# -----vim.rc------- | |
# set errorformat=%E\ %#[error]\ %#%f:%l:\ %m,%-Z\ %#[error]\ %p^,%-C\ %#[error]\ %m | |
# set errorformat+=,%W\ %#[warn]\ %#%f:%l:\ %m,%-Z\ %#[warn]\ %p^,%-C\ %#[warn]\ %m | |
# set errorformat+=,%-G%.%# | |
# noremap <silent> <Leader>ff :cf target/sbt.quickfix<CR> | |
# noremap <silent> <Leader>fn :cn<CR> | |
# ERRORS ONLY | |
# if echo "$line" | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" | grep '\[error\]' >> ${quickfix}.raw;\ | |
# WARNING AND ERRORS | |
#if echo "$line" | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" | grep '\[error\]\|\[warn\]' >> ${quickfix}.raw;\ | |
quickfix=target/sbt.quickfix;\ | |
sbt $@ | tee \ | |
>(while read line;\ | |
do \ | |
if echo "$line" | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" | grep '\[error\]\|\[warn\]' >> ${quickfix}.raw;\ | |
then sed -n '/\^/{x;d;};1h;1!{x;p;};${x;p;}' ${quickfix}.raw > $quickfix; fi;\ | |
done > /dev/null\ | |
) \ | |
>(clean=false; succeeded=true; while read line; \ | |
do \ | |
if echo "$line" | grep '^> .*$'; then clean=true; fi;\ | |
if $clean; then rm ${quickfix}.raw 2> /dev/null; rm $quickfix 2> /dev/null; clean=false; fi;\ | |
if echo "$line" | grep 'Waiting for source changes'; then\ | |
success=true; | |
if [ -s $quickfix ]; then success=false; message="Compilation failed"; icon="dialog-error"; else message="Compilation succeeded"; icon="dialog-information"; fi;\ | |
if [ $succeeded != $success ]; then notify-send "SBT" "$message" --icon=$icon --expire-time=2000; fi;\ | |
succeeded=$success;\ | |
clean=true;\ | |
fi \ | |
done > /dev/null\ | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment