-
Notifications
You must be signed in to change notification settings - Fork 0
/
color
executable file
·70 lines (67 loc) · 991 Bytes
/
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
70
#!/bin/bash
# Enable Color support
if tput colors > /dev/null 2>&1; then
# Default Color
C_DEF="\e[39m"
C_RED="\e[31m"
# Green
C_GRE="\e[32m"
# Yellow
C_YEL="\e[33m"
# Blue
C_BLU="\e[34m"
# Magenta
C_MAG="\e[35m"
# Cyan
C_CYA="\e[36m"
# Dark Gray
C_DGR="\e[90m"
# Now all the Light colors
# Light Gray
C_LGR="\e[37m"
# Red
C_LRE="\e[91m"
# Green
C_LGR="\e[92m"
# Yellow
C_LYE="\e[93m"
# Blue
C_LBL="\e[94m"
# Magenta
C_LMA="\e[95m"
# Cyan
C_LCY="\e[96m"
# White
C_WHI="\e[97m"
else
C_BLU=""
C_CYA=""
C_DEF=""
C_DGR=""
C_GRE=""
C_LBL=""
C_LCY=""
C_LGR=""
C_LMA=""
C_LRE=""
C_LYE=""
C_MAG=""
C_RED=""
C_WHI=""
fi
# Strips colors from input
colorstrip(){
if [ $# -eq 0 ] ; then
sed "s/\x1B\[[^m]*m//g"
else
echo "$@" | sed "s/\x1B\[[^m]*m//g"
fi
}
# Counts length of strings without colors
colorcount(){
if [ $# -eq 0 ] ; then
colorstrip | wc -c
else
echo "$@" | colorstrip | wc -c
fi
}