-
Notifications
You must be signed in to change notification settings - Fork 0
/
colorecho
executable file
·65 lines (53 loc) · 1.09 KB
/
colorecho
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
set -eu
usage() {
cat >&2 <<EOM
usage: $(basename "$0") [--dim] COLOR [options] [STRING...]
Echo STRING(s) to standard output. If standard output is a TTY, also echo the
standard TTY escapes for COLOR to print colorized output.
See \`help echo\` in bash for options passed to echo.
Options:
--dim Don't echo bold colors
Known colors, (aliases):
black (gray, grey)
red
green
yellow
blue
magenta (purple, violet)
cyan
white
EOM
}
bold=1
if [ $# -ge 1 ] && [ "$1" = "--dim" ]; then
bold=0
shift
fi
if [ $# -lt 1 ]; then
usage
exit 1
fi
case "$1" in
black|gray|grey) fg=30 ;;
red) fg=31 ;;
green) fg=32 ;;
yellow) fg=33 ;;
blue) fg=34 ;;
magenta|purple|violet) fg=35 ;;
cyan) fg=36 ;;
white) fg=37 ;;
*)
usage
echo >&2 "Unknown color: $1"
exit 1
;;
esac
shift
if [ -t 1 ]; then
echo -ne "\033[$bold;${fg}m"
fi
echo "$@"
if [ -t 1 ]; then
echo -ne "\033[m"
fi