Created
March 16, 2012 15:36
-
-
Save leedm777/2050580 to your computer and use it in GitHub Desktop.
Runs a program, stripping ANSI color codes from stdout and stderr
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
#!/bin/bash | |
# | |
# Runs a program, stripping ANSI color codes from stdout and stderr | |
# | |
# detect which sed to use | |
if test -z ${SED}; then | |
if cat /dev/null | sed -r '' 2> /dev/null ; then | |
SED=sed | |
elif cat /dev/null | gsed -r '' 2> /dev/null; then | |
SED=gsed | |
else | |
echo "Could not detect a sed that supports -r" >&2 | |
exit 1 | |
fi | |
fi | |
# FD's 3 and 4 are decolor'ed stdout/stdin, respectively | |
# script stolen from http://bit.ly/wK1Any | |
exec 3> >(${SED} -r 's:\x1B\[[0-9;]*[mK]::g' >&1) | |
exec 4> >(${SED} -r 's:\x1B\[[0-9;]*[mK]::g' >&2) | |
exec "$@" 1>&3 2>&4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment