Skip to content

Instantly share code, notes, and snippets.

@weiserr
Created February 10, 2016 09:41
Show Gist options
  • Save weiserr/d94836999da4005f7b13 to your computer and use it in GitHub Desktop.
Save weiserr/d94836999da4005f7b13 to your computer and use it in GitHub Desktop.
Colorized Maven Output
# Wrapper function for Maven's mvn command.
mvn-color()
{
# Formatting constants
BOLD=$(echo -e "\e[1m")
TEXT_RED=$(echo -e "\e[31m")
TEXT_GREEN=$(echo -e "\e[32m")
TEXT_YELLOW=$(echo -e "\e[33m")
TEXT_BLUE=$(echo -e "\e[34m")
RESET_FORMATTING=$(echo -e "\e[0m")
# Filter mvn output using sed
mvn-redirect $@ | sed -e "s/\(\[INFO\].*\)/${TEXT_BLUE}${BOLD}\1/g" \
-e "s/\(\[WARNING\].*\)/${BOLD}${TEXT_YELLOW}\1${RESET_FORMATTING}/g" \
-e "s/\(\[ERROR\].*\)/${BOLD}${TEXT_RED}\1${RESET_FORMATTING}/g" \
-e "s/Tests run: \([^,]*\), Failures: \([^,]*\), Errors: \([^,]*\), Skipped: \([^,]*\)/${BOLD}${TEXT_GREEN}Tests run: \1${RESET_FORMATTING}, Failures: ${BOLD}${TEXT_RED}\2${RESET_FORMATTING}, Errors: ${BOLD}${TEXT_RED}\3${RESET_FORMATTING}, Skipped: ${BOLD}${TEXT_YELLOW}\4${RESET_FORMATTING}/g"
# Make sure formatting is reset
echo -ne ${RESET_FORMATTING}
}
# 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