I have a small script that colorizes compiler(maven) output so errors won’t be overlooked anymore.
#!/bin/sh
export TEXT_YELLOW=`tput setaf 3`
export TEXT_RED=`tput setaf 1`
export RESET_FORMATTING=`tput sgr0`
mvn $* | sed \
-e "s/\(\[WARNING\].*\)/${TEXT_YELLOW}\1${RESET_FORMATTING}/g" \
-e "s/\(\[ERROR\].*\)/${TEXT_RED}\1${RESET_FORMATTING}/g"
Problem is the shell within a shell feature my compiler has (mvn cli:execute-phase). There a command prompt like maven2> should be visible on screen and the user is then able to type in commands. Unfortunately due to my script I see nothing but a blinking cursor. Only when I press the enter key the maven2> prompt-prefix-text pops up.
My guess is that sed is waiting for an EOL before it prints something on screen. To fix it I would have to look if the stream starts with the string maven2>. If it does then print out directly to terminal, otherwise forward it to sed. Is it possible in bash?
Okay, I found a solution. I tried a lot of things but was unable to solve the problem purely with bash in the end. So I wrote a python script instead and it works. Just pipe the maven output to the script like
mvn cli:execute-phase | colorize.py. It is also possible to write an alias in your bashrc so all maven calls have colorized output.