|
|
|
|
|
by jph
641 days ago
|
|
Yes and even better for faster speed and greater shell compatibility for basic colors, you can use this POSIX code: if [ -t 1 ] && [ -z "${NO_COLOR:-}" ]; then
COLOR_RESET='[0m'
COLOR_RED='[31m'
COLOR_GREEN='[32m'
COLOR_BLUE='[34m'
else
COLOR_RESET=''
COLOR_RED=''
COLOR_GREEN=''
COLOR_BLUE=''
fi
For more about this see Unix Shell Script Tactics: https://github.com/SixArm/unix-shell-script-tactics/tree/mai...Be aware there's an escape character at the start of each of color string, which is the POSIX equivalent of $'\e'; Hacker News seems to cut out that escape character. |
|