Skip to content

Commit

Permalink
refactor(coat/taoc): extract colorLines function; remove pipe w…
Browse files Browse the repository at this point in the history
…hen naked `cat` 🐈
  • Loading branch information
oldratlee committed Jan 24, 2024
1 parent a38e59f commit adefc1a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
18 changes: 13 additions & 5 deletions bin/coat
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,16 @@ rotateColorPrint() {
fi
}

# Bash read line does not read leading spaces
# https://stackoverflow.com/questions/29689172
cat "$@" | while IFS= read -r line; do
rotateColorPrint "$line"
done
colorLines() {
# Bash read line does not read leading spaces
# https://stackoverflow.com/questions/29689172
while IFS= read -r line; do
rotateColorPrint "$line"
done
}

if [ $# == 0 ]; then
colorLines
else
cat "$@" | colorLines
fi
14 changes: 9 additions & 5 deletions bin/taoc
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ rotateColorPrint() {
fi
}

# Bash read line does not read leading spaces
# https://stackoverflow.com/questions/29689172
tac "$@" | while IFS= read -r line; do
rotateColorPrint "$line"
done
colorLines() {
# Bash read line does not read leading spaces
# https://stackoverflow.com/questions/29689172
while IFS= read -r line; do
rotateColorPrint "$line"
done
}

tac "$@" | colorLines

0 comments on commit adefc1a

Please sign in to comment.