Skip to content

Commit 874dfb2

Browse files
small refactor and add fish shell support
1 parent d43ee44 commit 874dfb2

File tree

2 files changed

+49
-24
lines changed

2 files changed

+49
-24
lines changed

β€ŽREADME.mdβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ColorEchoForShell
2-
Make echo colorful with easier method. In [bash](https://www.gnu.org/software/bash/), [sh](https://en.wikipedia.org/wiki/Bourne_shell) and [zsh](http://www.zsh.org/).
2+
Make echo colorful with easier method. In [bash](https://www.gnu.org/software/bash/), [sh](https://en.wikipedia.org/wiki/Bourne_shell), [fish](http://fishshell.com/) and [zsh](http://www.zsh.org/).
33

44
## Installation
55

β€Žgenerator.shβ€Ž

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,37 @@
33
dist=dist/ColorEcho
44
table=table.txt
55

6-
for shell in sh bash
6+
for shell in sh bash fish
77
do
8+
if [ "$shell" = "bash" ]; then
9+
fn='function '
10+
dot='.'
11+
echo='echo'
12+
startSym='{'
13+
endSym='}'
14+
endIf='fi'
15+
brackets=
16+
para='@'
17+
elif [ "$shell" = "fish" ];then
18+
fn='function '
19+
dot='.'
20+
echo='echo'
21+
startSym=
22+
endSym='end'
23+
endIf='end'
24+
brackets=
25+
para='argv'
26+
else
27+
fn=
28+
dot=
29+
echo='/bin/echo'
30+
startSym='{'
31+
endSym='}'
32+
endIf='fi'
33+
brackets='()'
34+
para='@'
35+
fi
36+
837
newDist="$dist.$shell"
938
echo "#!/usr/bin/env $shell" > $newDist
1039
for color in `cat $table | awk '{print $1}'`
@@ -26,40 +55,36 @@ do
2655
for underLine in "" "UL"
2756
do
2857
echo "" >> $newDist
29-
if [ "$shell" = "bash" ]; then
30-
fn='function '
31-
dot='.'
32-
echo='echo'
33-
brackets=
34-
else
35-
fn=
36-
dot=
37-
echo='/bin/echo'
38-
brackets='()'
39-
fi
40-
echo "$fn""echo$dot$light$bold$underLine$color$brackets" >> $newDist
58+
echo "$fn""echo$dot$light$bold$underLine$color$brackets" >> $newDist
4159
if [ "$underLine" = "" ]; then
4260
ulCode=
4361
else
4462
ulCode='4;'
4563
fi
46-
echo "{" >> $newDist
47-
echo " $echo"' -e "\e['"$ulCode$bCode$code"$(grep $color $table | awk '{print $2}')'m$@\e[m"' >> $newDist
48-
echo "}" >> $newDist
64+
echo "$startSym" >> $newDist
65+
echo " $echo"' -e "\e['"$ulCode$bCode$code"$(grep $color $table | awk '{print $2}')'m$'$para'\e[m"' >> $newDist
66+
echo "$endSym" >> $newDist
4967
done
5068
done
5169
done
5270
done
5371

54-
echo "$fn echo"$dot"Rainbow$brackets" >> "$newDist"
72+
fnName="$fn echo"$dot"Rainbow$brackets"
73+
if [ "$shell" = "fish" ]; then
74+
ifCond="if type lolcat > /dev/null"
75+
else
76+
ifCond='if [ "type lolcat" ]; then'
77+
fi
78+
5579
cat << LOLCAT >> "$newDist"
56-
{
57-
if [ "type lolcat" ]; then
58-
echo "\$@" | lolcat
80+
$fnName
81+
$startSym
82+
$ifCond
83+
echo "\$$para" | lolcat
5984
else
60-
echo "\$@"
61-
fi
62-
}
85+
echo "\$$para"
86+
$endIf
87+
$endSym
6388
LOLCAT
6489

6590
done

0 commit comments

Comments
Β (0)