From 534d3511f785c1304d301f7eca22e295b56dde4b Mon Sep 17 00:00:00 2001 From: naskya Date: Fri, 27 Oct 2023 23:39:24 +0900 Subject: [PATCH] dev: don't print ANSI escape chars if stdout is piped/redirected --- update.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/update.sh b/update.sh index 85f24c3f2..6aa3f15af 100755 --- a/update.sh +++ b/update.sh @@ -1,16 +1,22 @@ #!/usr/bin/env bash set -eu +function color { + if [[ -t 1 ]]; then + tput setaf ${1:-7} + fi +} + function say { - tput setaf 5 + color 5 # magenta echo -e "( ^-^) < $1" - tput setaf 7 + color } function running { - tput setaf 3 + color 3 # yellow echo "[running] \$ $1" - tput setaf 7 + color } say "Start upgrading Firefish!"