cowsayeternal: Improve logging and printing

This commit is contained in:
Salt 2018-12-31 13:59:48 -06:00
parent b0ddc8ebaf
commit 847e09e119
1 changed files with 9 additions and 1 deletions

View File

@ -1,16 +1,24 @@
#!/bin/bash
cowsaidfile="$(mktemp)"
printf "Writing cows to temporary file \"%s\"\\n" \
"$cowsaidfile"
cowsay "E T E R N A L" > "$cowsaidfile"
trap_exit() {
printf "\\n"
cat "$cowsaidfile"
rm "$cowsaidfile"
}
trap trap_exit EXIT
iterations=1
while true; do
# Shut up shellcheck; that's the whole point. cowsay does a full read
# before it writes back to the file anyway.
# shellcheck disable=2094
cowsay -n < "$cowsaidfile" 1<> "$cowsaidfile"
printf "%s bytes of cowsay; hit Ctrl+C to dump them\\n" \
iterations=$(( iterations + 1 ))
# This line will only ever grow larger, so we don't need to clear it
# before overwriting it.
printf "\\r%s iterations, %s bytes of cowsay; hit Ctrl+C to dump them" \
"$iterations" \
"$(stat --printf="%s" "$cowsaidfile")"
done