Skip to content

Instantly share code, notes, and snippets.

Last active November 24, 2017 21:36
Show Gist options
  • Save evelyne24/7714094 to your computer and use it in GitHub Desktop.
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 and
The blog post explainig how to use this:
source $HOME/
#!/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`
# Wrapper function for Maven's mvn command.
# 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"
Copy link

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,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment