Skip to content

Commit adefc1a

Browse files
committed
refactor(coat/taoc): extract colorLines function; remove pipe when naked cat 🐈
1 parent a38e59f commit adefc1a

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

bin/coat

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,16 @@ rotateColorPrint() {
3030
fi
3131
}
3232

33-
# Bash read line does not read leading spaces
34-
# https://stackoverflow.com/questions/29689172
35-
cat "$@" | while IFS= read -r line; do
36-
rotateColorPrint "$line"
37-
done
33+
colorLines() {
34+
# Bash read line does not read leading spaces
35+
# https://stackoverflow.com/questions/29689172
36+
while IFS= read -r line; do
37+
rotateColorPrint "$line"
38+
done
39+
}
40+
41+
if [ $# == 0 ]; then
42+
colorLines
43+
else
44+
cat "$@" | colorLines
45+
fi

bin/taoc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ rotateColorPrint() {
3030
fi
3131
}
3232

33-
# Bash read line does not read leading spaces
34-
# https://stackoverflow.com/questions/29689172
35-
tac "$@" | while IFS= read -r line; do
36-
rotateColorPrint "$line"
37-
done
33+
colorLines() {
34+
# Bash read line does not read leading spaces
35+
# https://stackoverflow.com/questions/29689172
36+
while IFS= read -r line; do
37+
rotateColorPrint "$line"
38+
done
39+
}
40+
41+
tac "$@" | colorLines

0 commit comments

Comments
 (0)