-
Notifications
You must be signed in to change notification settings - Fork 0
/
colors.sh
77 lines (71 loc) · 1.22 KB
/
colors.sh
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
70
71
72
73
74
75
76
77
#!/bin/bash
#
# Colors a text background and foreground
# colors::background orange $(colors::foreground red This is a sample text)
colors_list() {
case "$1" in
blue)
echo 27 # 27 26 111 117 153
;;
blue-info)
echo 19
;;
green)
echo 22 # 22 28 70
;;
green-neon)
echo 10
;;
green-dark)
echo 22
;;
orange)
echo 202
;;
red)
echo 160 # 88 124 160 196
;;
red-bright)
echo 196
;;
violet)
echo 200
;;
yellow)
echo 220
;;
white)
echo 15
;;
silver)
echo 7
;;
*)
isInteger='^[0-9]+$'
if [[ $1 =~ $isInteger ]] ; then
echo "$1"
else
echo 27 # fallback color
fi
;;
esac
}
colors::foreground() {
local color=$(colors_list $1)
shift
echo -en "\033[38;5;${color}m\033[1m${@}\033[0m"
}
colors::background() {
local color=$(colors_list $1)
shift
echo -en "\033[48;5;${color}m\033[1m${@}\033[0m"
}
colors::ps1_fg() {
echo -en "\001\033[38;5;$(colors_list $1)m\033[1m\002"
}
colors::ps1_bg() {
echo -en "\001\033[48;5;$(colors_list $1)m\033[1m\002"
}
colors::ps1_reset() {
echo -en "\001\033[0m\002"
}