@@ -8,34 +8,34 @@ distPrefix="ColorEcho"
8
8
table=" color table.txt"
9
9
10
10
if [ ! -r " ${distFolder} /${distPrefix} .bash" ] || [ ! -s " ${distFolder} /${distPrefix} .bash" ]; then
11
- echo " ${distFolder}${distPrefix} .bash" is not readable, fallback to use origin echo
12
- alias echo.BoldRed=' echo'
13
- alias echo.BoldGreen=' echo'
14
- alias echo.BoldYellow=' echo'
11
+ echo " ${distFolder}${distPrefix} .bash" is not readable, fallback to use origin echo
12
+ alias echo.BoldRed=' echo'
13
+ alias echo.BoldGreen=' echo'
14
+ alias echo.BoldYellow=' echo'
15
15
else
16
- # use ColorEcho
17
- # shellcheck source=dist/ColorEcho.bash
18
- . " ${distFolder} /${distPrefix} .bash"
19
- command -v echo.BoldRed & > /dev/null || alias echo.BoldRed=' echo'
20
- command -v echo.BoldGreen & > /dev/null || alias echo.BoldGreen=' echo'
21
- command -v echo.BoldYellow & > /dev/null || alias echo.BoldYellow=' echo'
16
+ # use ColorEcho
17
+ # shellcheck source=dist/ColorEcho.bash
18
+ . " ${distFolder} /${distPrefix} .bash"
19
+ command -v echo.BoldRed & > /dev/null || alias echo.BoldRed=' echo'
20
+ command -v echo.BoldGreen & > /dev/null || alias echo.BoldGreen=' echo'
21
+ command -v echo.BoldYellow & > /dev/null || alias echo.BoldYellow=' echo'
22
22
fi
23
23
24
- mkdir -p $ distFolder
25
- if [ ! -w " $distFolder " ]; then
26
- echo.BoldRed " Dist folder - \" $distFolder \" is not writable, exit ..."
27
- exit 1;
24
+ mkdir -p " ${ distFolder} "
25
+ if [ ! -w " ${ distFolder} " ]; then
26
+ echo.BoldRed " Dist folder - \" ${ distFolder} \" is not writable, exit ..."
27
+ exit 1
28
28
fi
29
29
30
30
echo.BoldGreen " ColorEcho generator start!"
31
31
32
32
for shell in sh bash fish ksh zsh
33
33
do
34
- {
35
- echo.BoldYellow " Generating ColorEcho for $shell shell ..."
34
+ {
35
+ echo.BoldYellow " Generating ColorEcho for ${ shell} shell ..."
36
36
# shell specify configs and tricks
37
- case " $shell " in
38
- " bash" | " zsh" )
37
+ case " ${ shell} " in
38
+ " bash" | " zsh" )
39
39
fn=' function '
40
40
dot=' .'
41
41
echo=' echo'
44
44
endIf=' fi'
45
45
brackets=
46
46
para=' *'
47
- ;;
48
- " ksh" )
47
+ ;;
48
+ " ksh" )
49
49
fn=' function '
50
50
dot=
51
51
echo=' /bin/echo'
54
54
endIf=' fi'
55
55
brackets=
56
56
para=' *'
57
- ;;
58
- " fish" )
57
+ ;;
58
+ " fish" )
59
59
fn=' function '
60
60
dot=' .'
61
61
echo=' echo'
64
64
endIf=' end'
65
65
brackets=
66
66
para=' argv'
67
- ;;
68
- " sh" )
67
+ ;;
68
+ " sh" )
69
69
fn=
70
70
dot=
71
71
# shellcheck disable=SC2016
75
75
endIf=' fi'
76
76
brackets=' ()'
77
77
para=' *'
78
+ ;;
78
79
esac
79
80
80
81
newDist=" ${distFolder} /${distPrefix} .${shell} "
81
- touch " $newDist "
82
- if [ ! -w " $newDist " ]; then
83
- echo.BoldRed " dist file - \" $newDist \" is not writable, exit ..."
84
- exit 1
82
+ touch " ${ newDist} "
83
+ if [ ! -w " ${ newDist} " ]; then
84
+ echo.BoldRed " dist file - \" ${ newDist} \" is not writable, exit ..."
85
+ exit 1
85
86
fi
86
87
87
- echo " #!/usr/bin/env $shell " > " $newDist "
88
- if [ " $shell " = " sh" ]; then
89
- cat << SH_ECHO >> "$newDist "
88
+ echo " #!/usr/bin/env ${ shell} " > " ${ newDist} "
89
+ if [ " ${ shell} " = " sh" ]; then
90
+ cat << SH_ECHO >> "${ newDist} "
90
91
if [ "\$ (uname)" = "FreeBSD" ]; then
91
92
ECHO="echo"
92
93
else
93
94
ECHO="/bin/echo"
94
95
fi
95
96
SH_ECHO
96
97
fi
97
- awk ' {print $1}' " $table " | while IFS= read -r color
98
+ awk ' {print $1}' " ${ table} " | while IFS= read -r color
98
99
do
99
- # light or not
100
- for light in " " " Light"
100
+ # light or not
101
+ for light in " " " Light"
102
+ do
103
+ if [ " ${light} " = " " ]; then
104
+ code=3
105
+ else
106
+ code=9
107
+ fi
108
+ # bold or not
109
+ for bold in " " " Bold"
101
110
do
102
- if [ " $light " = " " ]; then
103
- code=3
104
- else
105
- code=9
106
- fi
107
- # bold or not
108
- for bold in " " " Bold"
109
- do
110
- if [ " $bold " = " " ]; then
111
- bCode=
112
- else
113
- bCode=' 1;'
114
- fi
115
- # underline or not
116
- for underLine in " " " UL"
117
- do
118
- {
119
- echo " "
120
- echo " ${fn} echo${dot}${light}${bold}${underLine}${color}${brackets} "
121
- if [ " $underLine " = " " ]; then
122
- ulCode=
123
- else
124
- ulCode=' 4;'
125
- fi
126
- # write the code down
127
- echo " $startSym "
128
- echo " $echo " ' -e "\033[' " ${ulCode}${bCode}${code} " " $( grep " $color " " $table " | awk ' {print $2}' ) " ' m$' " $para " ' \033[m"'
129
- echo " $endSym "
130
- } >> " $newDist "
131
- done
132
- done
111
+ if [ " ${bold} " = " " ]; then
112
+ bCode=
113
+ else
114
+ bCode=' 1;'
115
+ fi
116
+ # underline or not
117
+ for underLine in " " " UL"
118
+ do
119
+ {
120
+ echo " "
121
+ echo " ${fn} echo${dot}${light}${bold}${underLine}${color}${brackets} "
122
+ if [ " ${underLine} " = " " ]; then
123
+ ulCode=
124
+ else
125
+ ulCode=' 4;'
126
+ fi
127
+ # write the code down
128
+ echo " ${startSym} "
129
+ echo " ${echo} " ' -e "\033[' " ${ulCode}${bCode}${code} " " $( grep " ${color} " " ${table} " | awk ' {print $2}' ) " ' m$' " ${para} " ' \033[m"'
130
+ echo " ${endSym} "
131
+ } >> " ${newDist} "
132
+ done
133
133
done
134
+ done
134
135
done
135
136
136
137
# rainbow output relys on lolcat
137
138
fnName=" ${fn} echo${dot} Rainbow${brackets} "
138
- case " $shell " in
139
- " fish" )
140
- ifCond=" if which lolcat > /dev/null"
139
+ case " ${ shell} " in
140
+ " fish" )
141
+ ifCond=" if which lolcat > /dev/null"
141
142
;;
142
- " ksh" )
143
- ifCond=' if which lolcat 2> /dev/null >&2; then'
143
+ " ksh" )
144
+ ifCond=' if which lolcat 2> /dev/null >&2; then'
144
145
;;
145
- * )
146
- ifCond=' if which lolcat > /dev/null 2>&1; then'
146
+ * )
147
+ ifCond=' if which lolcat > /dev/null 2>&1; then'
147
148
;;
148
149
esac
149
150
150
- cat << LOLCAT >> "$newDist "
151
- $fnName
152
- $startSym
153
- $ifCond
154
- echo "\$ $para " | lolcat
151
+ cat << LOLCAT >> "${ newDist} "
152
+ ${ fnName}
153
+ ${ startSym}
154
+ ${ ifCond}
155
+ echo "\$ ${ para} " | lolcat
155
156
else
156
- echo "\$ $para "
157
- $endIf
158
- $endSym
157
+ echo "\$ ${ para} "
158
+ ${ endIf}
159
+ ${ endSym}
159
160
LOLCAT
160
161
161
162
# echo.Reset to remove color code on output
162
163
fnName=" ${fn} echo${dot} Reset${brackets} "
163
- cat << RESET >> "$newDist "
164
- $fnName
165
- $startSym
166
- echo "\$ $para " | tr -d '[:cntrl:]' | sed -E "s/\\ [((;)?[0-9]{1,3}){0,3}m//g"
167
- $endSym
164
+ cat << RESET >> "${ newDist} "
165
+ ${ fnName}
166
+ ${ startSym}
167
+ echo "\$ ${ para} " | tr -d '[:cntrl:]' | sed -E "s/\\ [((;)?[0-9]{1,3}){0,3}m//g"
168
+ ${ endSym}
168
169
RESET
169
- } &
170
+ } &
170
171
done
171
172
172
173
wait
0 commit comments