Last active
November 24, 2017 21:36
-
-
Save evelyne24/7714094 to your computer and use it in GitHub Desktop.
I've been using Maven for Android projects quite extensively from command line lately and I found that a colour output is really helpful.I'm using iTerm2 on MacOs Mavericks (10.9). I've found a couple of bash scripts to colorise Maven output but none was quite enough for me :PThe two best I found are https://gist.github.com/mike-ensor/1881211 and …
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
The blog post explainig how to use this: http://android.codeandmagic.org/colorize-maven-output/ | |
source $HOME/.mvn_colour.sh |
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 | |
# Notes | |
# In MacOS, + does not work for regex, nor -E flag. | |
# Instead I used \{1,\} for char repetition. | |
# Formatting constants | |
bold=`tput bold` | |
red=`tput setaf 1` | |
bg_red=`tput setab 1` | |
green=`tput setaf 2` | |
yellow=`tput setaf 3` | |
blue=`tput setaf 4` | |
magenta=`tput setaf 5` | |
cyan=`tput setaf 6` | |
grey=`tput setaf 7` | |
white=`tput sgr0` | |
end=`tput sgr0` | |
info=${white} | |
debug=${grey} | |
success=${green} | |
warn=${yellow} | |
error=${bold}${red} | |
skipped=${grey} | |
downloading=${cyan} | |
projdash=${cyan} | |
projname=${bold}${cyan} | |
plugdash=${blue} | |
plugname=${bold}${blue} | |
# Wrapper function for Maven's mvn command. | |
mvn-color() | |
{ | |
# Filter mvn output using sed | |
mvn $@ | sed -e "s/\(\[INFO\]\) Building \(.*\)/${info}\1${end} ${projname}Building \2${end}/g" \ | |
-e "s/\(\[INFO\]\) \(\-\{1,\}\) \(.*\) \(\-\{1,\}\)/${info}\1${end} ${plugdash}\2${end} ${plugname}\3${end} ${plugdash}\4${end}/g" \ | |
-e "s/\(\[INFO\]\) \(\-*\)/${info}\1${end} ${projdash}\2${end}/g" \ | |
-e "s/\(\[DEBUG\].*\)/${debug}\1${end}/g" \ | |
-e "s/\(\[WARNING\].*\)/${warn}\1${end}/g" \ | |
-e "s/\(\[ERROR\].*\)/${error}\1${end}/g" \ | |
-e "s/SUCCESS \(\[[0-9]*.[0-9]*s\]\)/${success}SUCCESS \1${end}/g" \ | |
-e "s/FAILURE \(\[[0-9]*.[0-9]*s\]\)/${error}FAILURE \1${end}/g" \ | |
-e "s/SKIPPED/${skipped}SKIPPED${end}/g" \ | |
-e "s/BUILD FAILURE/${error}BUILD FAILURE${end}/g" \ | |
-e "s/BUILD SUCCESS/${success}BUILD SUCCESS${end}/g" \ | |
-e "s/\(<<< FAILURE!\)/${error}\1${end}/g" \ | |
-e "s/\(<<< ERROR!\)/${error}\1${end}/g" \ | |
-e "s/Caused by: \(.*\)/${white}${bg_red}Caused by: \1${end}/g" \ | |
-e "s/Tests run: \([0-9]*\), Failures: \([0-9]*\), Errors: \([0-9]*\), Skipped: \([0-9]*\)/${success}Tests run: \1 ${end}, ${warn}Failures: \2 ${end}, ${error}Errors: \3 ${end}, ${skipped}Skipped: \4 ${end}/g" | |
# Make sure formatting is reset | |
echo -ne ${end} | |
} | |
# Override the mvn command with the colorized one. | |
alias mvn="mvn-color" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This looks very useful :)
But for the life of me I cannot get it to work. I need to run my maven using cygwin unfortunately so I don't know if that is an issue.
Could you explain to me how I use your script? (It's Friday and my brain already thinks its the weekend)
Many thanks,
Paul