3
3
set -e
4
4
shopt -s expand_aliases
5
5
6
- distFolder=dist
7
- distPrefix=ColorEcho
6
+ distFolder=" dist"
7
+ distPrefix=" ColorEcho"
8
8
table=" color table.txt"
9
9
10
- if [ ! -r " $distFolder / $ distPrefix" .bash ] || [ ! -s " $distFolder / $ distPrefix" .bash ]; then
11
- echo " $distFolder$ distPrefix " .bash is not readable, fallback to use origin echo
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
12
alias echo.Red=' echo'
13
13
alias echo.Green=' echo'
14
14
alias echo.BoldYellow=' echo'
15
15
else
16
16
# use ColorEcho
17
- . " $distFolder /$distPrefix " .bash
17
+ . " ${distFolder} /${distPrefix} .bash"
18
+ command -v echo.Red & > /dev/null || alias echo.Red=' echo'
19
+ command -v echo.Green & > /dev/null || alias echo.Green=' echo'
20
+ command -v echo.BoldYellow & > /dev/null || alias echo.BoldYellow=' echo'
18
21
fi
19
22
20
23
mkdir -p $distFolder
21
24
if [ ! -w " $distFolder " ]; then
22
- echo.Red Dist folder - $distFolder is not writable, exit ...
25
+ echo.Red " Dist folder - \" $distFolder \" is not writable, exit ..."
23
26
exit 1;
24
27
fi
25
28
26
- echo.Green ColorEcho generator start!
29
+ echo.Green " ColorEcho generator start!"
27
30
28
31
for shell in sh bash fish ksh zsh
29
32
do
30
- echo.BoldYellow Generating ColorEcho for $shell shell ...
33
+ echo.BoldYellow " Generating ColorEcho for $shell shell ..."
31
34
# shell specify configs and tricks
32
- case $shell in
35
+ case " $shell " in
33
36
" bash" | " zsh" )
34
37
fn=' function '
35
38
dot=' .'
71
74
para=' @'
72
75
esac
73
76
74
- newDist=" $distFolder / $ distPrefix. $ shell"
75
- touch $newDist
77
+ newDist=" ${ distFolder} / ${ distPrefix} . ${ shell} "
78
+ touch " $newDist "
76
79
if [ ! -w " $newDist " ]; then
77
- echo.Red dist file - " $newDist " is not writable, exit ...
80
+ echo.Red " dist file - \ "$newDist \ " is not writable, exit ..."
78
81
exit 1
79
82
fi
80
83
81
- echo " #!/usr/bin/env $shell " > $newDist
82
- for color in ` cat " $table " | awk ' {print $1}' `
84
+ echo " #!/usr/bin/env $shell " > " $newDist "
85
+ for color in $( awk ' {print $1}' " $table " )
83
86
do
84
87
# light or not
85
88
for light in " " " Light"
100
103
# underline or not
101
104
for underLine in " " " UL"
102
105
do
103
- echo " " >> $newDist
104
- echo " $fn " " echo$dot$light$bold$underLine$color$brackets " >> $newDist
105
- if [ " $underLine " = " " ]; then
106
- ulCode=
107
- else
108
- ulCode=' 4;'
109
- fi
110
- # write the code down
111
- echo " $startSym " >> $newDist
112
- echo " $echo " ' -e "\e[' " $ulCode$bCode$code " $( grep $color " $table " | awk ' {print $2}' ) ' m$' $para ' \e[m"' >> $newDist
113
- echo " $endSym " >> $newDist
106
+ {
107
+ echo " "
108
+ echo " ${fn} echo${dot}${light}${bold}${underLine}${color}${brackets} "
109
+ if [ " $underLine " = " " ]; then
110
+ ulCode=
111
+ else
112
+ ulCode=' 4;'
113
+ fi
114
+ # write the code down
115
+ echo " $startSym "
116
+ echo " $echo " ' -e "\e[' " ${ulCode}${bCode}${code} " $( grep $color " $table " | awk ' {print $2}' ) ' m$' $para ' \e[m"'
117
+ echo " $endSym "
118
+ } >> " $newDist "
114
119
done
115
120
done
116
121
done
117
122
done
118
123
119
124
# rainbow output relys on lolcat
120
- fnName=" $fn echo" $ dot" Rainbow$brackets "
125
+ fnName=" ${fn} echo${ dot} Rainbow${ brackets} "
121
126
if [ " $shell " = " fish" ]; then
122
127
ifCond=" if type lolcat > /dev/null"
123
128
else
@@ -136,7 +141,7 @@ $endSym
136
141
LOLCAT
137
142
138
143
# echo.Reset to remove color code on output
139
- fnName=" $fn echo" $ dot" Reset$brackets "
144
+ fnName=" ${fn} echo${ dot} Reset${ brackets} "
140
145
cat << LOLCAT >> "$newDist "
141
146
$fnName
142
147
$startSym
@@ -146,4 +151,4 @@ LOLCAT
146
151
147
152
done
148
153
149
- echo.Green ColorEcho generator end!
154
+ echo.Green " ColorEcho generator end!"
0 commit comments