Skip to content

Commit 0103b94

Browse files
Improve coding style and change indent to 2 spaces
1 parent 20c1068 commit 0103b94

File tree

6 files changed

+92
-91
lines changed

6 files changed

+92
-91
lines changed

β€Žgenerator.sh

Lines changed: 87 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,34 @@ distPrefix="ColorEcho"
88
table="color table.txt"
99

1010
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'
1515
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'
2222
fi
2323

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
2828
fi
2929

3030
echo.BoldGreen "ColorEcho generator start!"
3131

3232
for shell in sh bash fish ksh zsh
3333
do
34-
{
35-
echo.BoldYellow "Generating ColorEcho for $shell shell ..."
34+
{
35+
echo.BoldYellow "Generating ColorEcho for ${shell} shell ..."
3636
#shell specify configs and tricks
37-
case "$shell" in
38-
"bash" | "zsh")
37+
case "${shell}" in
38+
"bash" | "zsh")
3939
fn='function '
4040
dot='.'
4141
echo='echo'
@@ -44,8 +44,8 @@ do
4444
endIf='fi'
4545
brackets=
4646
para='*'
47-
;;
48-
"ksh")
47+
;;
48+
"ksh")
4949
fn='function '
5050
dot=
5151
echo='/bin/echo'
@@ -54,8 +54,8 @@ do
5454
endIf='fi'
5555
brackets=
5656
para='*'
57-
;;
58-
"fish")
57+
;;
58+
"fish")
5959
fn='function '
6060
dot='.'
6161
echo='echo'
@@ -64,8 +64,8 @@ do
6464
endIf='end'
6565
brackets=
6666
para='argv'
67-
;;
68-
"sh")
67+
;;
68+
"sh")
6969
fn=
7070
dot=
7171
# shellcheck disable=SC2016
@@ -75,98 +75,99 @@ do
7575
endIf='fi'
7676
brackets='()'
7777
para='*'
78+
;;
7879
esac
7980

8081
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
8586
fi
8687

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}"
9091
if [ "\$(uname)" = "FreeBSD" ]; then
9192
ECHO="echo"
9293
else
9394
ECHO="/bin/echo"
9495
fi
9596
SH_ECHO
9697
fi
97-
awk '{print $1}' "$table" | while IFS= read -r color
98+
awk '{print $1}' "${table}" | while IFS= read -r color
9899
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"
101110
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
133133
done
134+
done
134135
done
135136

136137
#rainbow output relys on lolcat
137138
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"
141142
;;
142-
"ksh")
143-
ifCond='if which lolcat 2> /dev/null >&2; then'
143+
"ksh")
144+
ifCond='if which lolcat 2> /dev/null >&2; then'
144145
;;
145-
*)
146-
ifCond='if which lolcat > /dev/null 2>&1; then'
146+
*)
147+
ifCond='if which lolcat > /dev/null 2>&1; then'
147148
;;
148149
esac
149150

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
155156
else
156-
echo "\$$para"
157-
$endIf
158-
$endSym
157+
echo "\$${para}"
158+
${endIf}
159+
${endSym}
159160
LOLCAT
160161

161162
#echo.Reset to remove color code on output
162163
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}
168169
RESET
169-
} &
170+
} &
170171
done
171172

172173
wait

β€Žtest-scripts/bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ script="${dir}/../dist/ColorEcho.bash"
77

88
awk '/^function +echo/ {print $2}' "${script}" | while IFS= read -r x
99
do
10-
$x "$x"
10+
${x} "${x}"
1111
done

β€Žtest-scripts/fish

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ set script "$dir/../dist/ColorEcho.fish"
55
. "$script"
66

77
for x in (awk '/^function +echo/ {print $2}' "$script")
8-
eval $x "$x"
8+
eval $x "$x"
99
end

β€Žtest-scripts/ksh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ script="${dir}/../dist/ColorEcho.ksh"
77

88
awk '/^function +echo/ {print $2}' "${script}" | while IFS= read -r x
99
do
10-
$x "$x"
10+
${x} "${x}"
1111
done

β€Žtest-scripts/sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ script="${dir}/../dist/ColorEcho.sh"
77

88
grep -E "echo[a-zA-Z]+()" "${script}" | sed 's/()//g' | while IFS= read -r x
99
do
10-
$x "$x"
10+
${x} "${x}"
1111
done

β€Žtest-scripts/zsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ script="${dir}/../dist/ColorEcho.zsh"
77

88
awk '/^function +echo/ {print $2}' "${script}" | while IFS= read -r x
99
do
10-
$x "$x"
10+
${x} "${x}"
1111
done

0 commit comments

Comments
Β (0)