2018-12-21 13:46:10 -06:00
|
|
|
#!/bin/bash
|
2018-12-21 15:26:17 -06:00
|
|
|
cowsaidfile="$(mktemp)"
|
2018-12-31 13:59:48 -06:00
|
|
|
printf "Writing cows to temporary file \"%s\"\\n" \
|
|
|
|
"$cowsaidfile"
|
2018-12-21 15:26:17 -06:00
|
|
|
cowsay "E T E R N A L" > "$cowsaidfile"
|
2018-12-21 13:46:10 -06:00
|
|
|
trap_exit() {
|
2018-12-31 14:05:15 -06:00
|
|
|
# kill "$cowthreadpid" > /dev/null 2>&1
|
|
|
|
wait "$cowthreadpid"
|
2018-12-31 13:59:48 -06:00
|
|
|
printf "\\n"
|
2018-12-21 15:26:17 -06:00
|
|
|
cat "$cowsaidfile"
|
|
|
|
rm "$cowsaidfile"
|
2018-12-21 13:46:10 -06:00
|
|
|
}
|
|
|
|
trap trap_exit EXIT
|
2018-12-31 14:05:15 -06:00
|
|
|
# Cow writing thread
|
|
|
|
(
|
2018-12-21 13:46:10 -06:00
|
|
|
while true; do
|
2018-12-21 15:26:17 -06:00
|
|
|
# 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"
|
2018-12-31 14:05:15 -06:00
|
|
|
done
|
|
|
|
) &
|
|
|
|
cowthreadpid=$!
|
|
|
|
while true; do
|
2018-12-31 13:59:48 -06:00
|
|
|
# This line will only ever grow larger, so we don't need to clear it
|
|
|
|
# before overwriting it.
|
2018-12-31 14:05:15 -06:00
|
|
|
printf "\\r%s bytes of cowsay; hit Ctrl+C to dump them" \
|
2018-12-21 15:26:17 -06:00
|
|
|
"$(stat --printf="%s" "$cowsaidfile")"
|
2018-12-31 14:05:15 -06:00
|
|
|
sleep 0.02
|
2018-12-21 13:46:10 -06:00
|
|
|
done
|