Bash – Alternative to watch which support colors

bashUtilitieswatch

I have a command (phpunit) which has a colored output. According to the watch, command I should be able to use the --color flag to allow color rendering to pass through. However, this isn't working. Is there any other ways of solving this?

Best Answer

phpunit | cat didn't work (signalling that this is not a problem with watch but the phpunit command).

As an alternative, the following bash script approach worked great for me:

#!/bin/bash
while true; do
    (echo -en '\033[H'
        CMD="$@"
        bash -c "$CMD" | while read LINE; do 
            echo -n "$LINE"
            echo -e '\033[0K' 
        done
        echo -en '\033[J') | tac | tac 
    sleep 2 
done

Usage:

$ botch my-command
Related Question