forked from oldratlee/useful-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
a2l
executable file
·30 lines (25 loc) · 755 Bytes
/
a2l
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash
# @Function
# echo each arguments on one line colorfully.
#
# @Usage
# $ ./a2l arg1 arg2
# $ ./a2l *.txt
#
# @online-doc https://github.com/oldratlee/useful-scripts/blob/master/docs/shell.md#-a2l
# @author Jerry Lee (oldratlee at gmail dot com)
# NOTE: $'foo' is the escape sequence syntax of bash
readonly ec=$'\033' # escape char
readonly eend=$'\033[0m' # escape end
colorEcho() {
local color="$1"
shift
# check isatty in bash https://stackoverflow.com/questions/10022323
# if stdout is console, turn on color output.
[ -t 1 ] && echo "$ec[1;${color}m$@$eend" || echo "$@"
}
readonly -a ECHO_COLORS=(31 32 37 34 33 35 36)
COUNT=0
for a; do
colorEcho "${ECHO_COLORS[COUNT++ % ${#ECHO_COLORS[@]}]}" "$a"
done