Skip to content

Commit 1358723

Browse files
committed
improve coat
1 parent aa7e222 commit 1358723

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

coat

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
set -e
1414
set -o pipefail
1515

16+
# if not in console, use cat directly
17+
# check isatty in bash https://stackoverflow.com/questions/10022323
18+
[ ! -t 1 ] && exec cat "$@"
19+
1620
# NOTE: $'foo' is the escape sequence syntax of bash
1721
readonly ec=$'\033' # escape char
1822
readonly eend=$'\033[0m' # escape end
@@ -21,9 +25,7 @@ readonly -a ECHO_COLORS=(31 32 37 34 33 35 36)
2125
COUNT=0
2226
colorEcho() {
2327
local color="${ECHO_COLORS[COUNT++ % ${#ECHO_COLORS[@]}]}"
24-
# check isatty in bash https://stackoverflow.com/questions/10022323
25-
# if stdout is console, turn on color output.
26-
[ -t 1 ] && echo "$ec[1;${color}m$@$eend" || echo "$@"
28+
echo "$ec[1;${color}m$@$eend"
2729
}
2830

2931
# Bash read line does not read leading spaces https://stackoverflow.com/questions/29689172

0 commit comments

Comments
 (0)