-
Notifications
You must be signed in to change notification settings - Fork 1
/
Echo.sh
69 lines (66 loc) · 1.71 KB
/
Echo.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
# Echo printing utility
# README
# Installation: Run `source Echo.sh "PREFIX"`
# Use command `Echo [FLAGS] MSG` instead of `echo [FLAGS] MSG` to print out your
# PREFIX on every line
# Overwrite prefix with `EchoPrefix=PREFIX` to change prefix
# Inside your print messages, insert `$(EchoColor COLOR)` to change color
# By default, `$(EchoColor)` will reset text color to default
# Boolean class
True=0
False=1
Boolean() {
return $1
}
EchoPrefix="Echo"
if [[ "$@" != "" ]]; then
EchoPrefix="$@"
fi
EchoPrefixCurrent="$EchoPrefix"
EchoColor() {
ColorCode="0m"
case $1 in
Black) ColorCode="0;30m";;
Red) ColorCode="0;31m";;
Green) ColorCode="0;32m";;
Orange) ColorCode="0;33m";;
Blue) ColorCode="0;34m";;
Purple) ColorCode="0;35m";;
Cyan) ColorCode="0;36m";;
LightGray) ColorCode="0;37m";;
DarkGray) ColorCode="1;30m";;
LightRed) ColorCode="1;31m";;
LightGreen) ColorCode="1;32m";;
Yellow) ColorCode="1;33m";;
LightBlue) ColorCode="1;34m";;
LightPurple) ColorCode="1;35m";;
LightCyan) ColorCode="1;36m";;
White) ColorCode="1;37m";;
esac
echo -e "\033[0;$ColorCode"
}
Echo() {
EchoHasFlags=$True
EchoFlags=""
while Boolean $EchoHasFlags; do
if [[ $1 == "-n" || $1 == "-e" || $1 == "-E" ]]; then
EchoFlags+="$1 "
shift
else
EchoHasFlags=$False
fi
done
if [[ "$EchoPrefixCurrent" != "" ]]; then
EchoPrefixCurrent="$EchoPrefix"
fi
echo $EchoFlags "$EchoPrefixCurrent $@"
if echo "${EchoFlags//-/\-}" | grep -q "\-n"; then
EchoPrefixCurrent=""
else
EchoPrefixCurrent="$EchoPrefix"
fi
}
Read() {
read $@
EchoPrefixCurrent="$EchoPrefix"
}