/
color
executable file
·69 lines (63 loc) · 1.34 KB
/
color
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
66
67
68
69
#!/usr/bin/env bash
# set colors, separate multiple selections with comma, order is not important
# using bold in one definition requires resetting it in others with offbold
# using background in one color requires resetting it in others with bdefault
# example:
# rvm_error_color=bold,red
# rvm_notify_color=offbold,green
case "${TERM:-dumb}" in
(dumb|unknown) exit 0 ;;
esac
builtin command -v tput >/dev/null && tput sgr0 >/dev/null || exit 0
for color in ${1//,/ }
do
case "${color:-}" in
# regular colors
black) tput setaf 0
;;
red) tput setaf 1
;;
green) tput setaf 2
;;
yellow) tput setaf 3
;;
blue) tput setaf 4
;;
magenta) tput setaf 5
;;
cyan) tput setaf 6
;;
white) tput setaf 7
;;
# emphasized (bolded) colors
bold) tput smso
;;
offbold) tput rmso
;;
# background colors
bblack) tput setab 0
;;
bred) tput setab 1
;;
bgreen) tput setab 2
;;
byellow) tput setab 3
;;
bblue) tput setab 4
;;
bmagenta) tput setab 5
;;
bcyan) tput setab 6
;;
bwhite) tput setab 7
;;
# Defaults
default) tput setaf 9
;;
bdefault) tput setab 9
;;
# Reset
*) tput sgr0
;;
esac
done