-
-
Save dant3/7444827 to your computer and use it in GitHub Desktop.
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 | |
# Formatting constants | |
BOLD=`tput bold` | |
UNDERLINE_ON=`tput smul` | |
UNDERLINE_OFF=`tput rmul` | |
TEXT_BLACK=`tput setaf 0` | |
TEXT_RED=`tput setaf 1` | |
TEXT_GREEN=`tput setaf 2` | |
TEXT_YELLOW=`tput setaf 3` | |
TEXT_BLUE=`tput setaf 4` | |
TEXT_MAGENTA=`tput setaf 5` | |
TEXT_CYAN=`tput setaf 6` | |
TEXT_WHITE=`tput setaf 7` | |
BACKGROUND_BLACK=`tput setab 0` | |
BACKGROUND_RED=`tput setab 1` | |
BACKGROUND_GREEN=`tput setab 2` | |
BACKGROUND_YELLOW=`tput setab 3` | |
BACKGROUND_BLUE=`tput setab 4` | |
BACKGROUND_MAGENTA=`tput setab 5` | |
BACKGROUND_CYAN=`tput setab 6` | |
BACKGROUND_WHITE=`tput setab 7` | |
RESET_FORMATTING=`tput sgr0` | |
# Wrapper function for Maven's mvn command. | |
mvn-color() | |
{ | |
# Filter mvn output using sed | |
mvn $@ | sed -e "s/\(\[INFO\]\ \-.*\)/${BOLD}\1${RESET_FORMATTING}/g" \ | |
-e "s/\(\[INFO\]\ \[.*\)/${RESET_FORMATTING}${BOLD}\1${RESET_FORMATTING}/g" \ | |
-e "s/\(\[INFO\]\ BUILD SUCCESSFUL\)/${BOLD}${TEXT_GREEN}\1${RESET_FORMATTING}/g" \ | |
-e "s/\(\[debug\].*\)/${TEXT_CYAN}\1${RESET_FORMATTING}/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
Very nice! This is a much improved version of what I had hiding in my bashrc