-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcolor_echo
executable file
·40 lines (39 loc) · 2.09 KB
/
color_echo
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
#!/bin/bash
# Some examples:
# color_echo RED Error: something bad happened
# color_echo --ERROR Error: something bad happened
# color_echo RED this is in red CYAN this is in cyan LRED this is the light red RESET rest is normal
# color_echo RED this wont print escape characters into files > file
# color_echo RED this also wont have colored output | more
for word in "$@"; do
# test if output is terminal, use colors only if its a terminal
if test -t 1; then
case "$word" in
NORMAL|RESET) echo -n -e "\033[0;00m";;
BLACK) echo -n -e "\033[22;30m";;
RED|--ERROR|--ERR) echo -n -e "\033[22;31m";;
GREEN|--INFO) echo -n -e "\033[22;32m";;
YELLOW|--WARNING|--WARN) echo -n -e "\033[22;33m";;
BLUE) echo -n -e "\033[22;34m";;
MAGENTA) echo -n -e "\033[22;35m";;
CYAN) echo -n -e "\033[22;36m";;
GRAY|WHITE) echo -n -e "\033[22;37m";;
LGRAY|DARKGRAY|BRIGHTBLACK|--DEBUG) echo -n -e "\033[01;30m";;
LRED|LIGHTRED|BRIGHTRED|--FATAL) echo -n -e "\033[01;31m";;
LGREEN|LIGHTGREEN|BRIGHTGREEN) echo -n -e "\033[01;32m";;
LYELLOW|LIGHTYELLOW|BRIGHTYELLOW) echo -n -e "\033[01;33m";;
LBLUE|LIGHTBLUE|BRIGHTBLUE) echo -n -e "\033[01;34m";;
LMAGENTA|LIGHTMAGENTA|BRIGHTMAGENTA) echo -n -e "\033[01;35m";;
LCYAN|LIGHTCYAN|BRIGHTCYAN) echo -n -e "\033[01;36m";;
LWHITE|LIGHTWHITE|BRIGHTWHITE) echo -n -e "\033[01;37m";;
*) echo -n "$word ";;
esac
else
# so output should be a file, dont print any color
case "$word" in
NORMAL|RESET|BLACK|RED|--ERROR|--ERR|GREEN|--INFO|YELLOW|--WARNIN|--WARN|BLUE|MAGENTA|CYAN|GRAY|WHITE|LGRAY|DARKGRAY|BRIGHTBLACK|--DEBUG|LRED|LIGHTRED|BRIGHTRED|--FATAL|LGREEN|LIGHTGREEN|BRIGHTGREEN|LYELLOW|LIGHTYELLOW|BRIGHTYELLOW|LBLUE|LIGHTBLUE|BRIGHTBLUE|LMAGENTA|LIGHTMAGENTA|BRIGHTMAGENTA|LCYAN|LIGHTCYAN|BRIGHTCYAN|LWHITE|LIGHTWHITE|BRIGHTWHITE): ;;
*) echo -n "$word ";;
esac
fi
done
test -t 1 && echo -e "\033[0;00m" || echo