From 735fd25cf857d122a7db36da90b57ac79163b0e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= <cynerd@email.cz> Date: Fri, 24 Jan 2020 12:04:32 +0100 Subject: [PATCH] helpers/common: let user optionally decide if output is TTY --- helpers/common.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/helpers/common.sh b/helpers/common.sh index 6ec6001d9..a595124dd 100644 --- a/helpers/common.sh +++ b/helpers/common.sh @@ -15,12 +15,19 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. ## Common printing functions ############ + +# Detect tty if IS_TTY not already set +if [ -z "${IS_TTY+x}" ]; then + export IS_TTY="" + [ -t 2 ] && IS_TTY="1" +fi + _color_echo() { local name="$1" local color="$2" local text="$3" shift 2 - if [ -t 2 ] || [ -n "$IS_TTY" ]; then + if [ -n "$IS_TTY" ]; then echo -e "\033[${color}m${text}"'\033[0m' >&2 else echo "$name: $text" >&2 -- GitLab