bash-spinner
bash-spinner copied to clipboard
great starting point, but found a few issues
Thanks! This script inspired me to build a progress spinner for some scripts I'm writing.
I have found a few issues though:
- if
stop_spinner
is called immediately afterstart_spinner
(or some operation completes very quickly), the output gets a bit messed up. This is becausestop_spinner
doesn't wait for the spinner job to terminate before writing to the terminal. This can be accomplished with a simplewait ${_sp_pid}
. - all messages are written to stdout, where stderr is usually meant for these sorts of applications. Stdout is a buffered stream, and stderr is not, so stderr will actually work a bit better (less flickering).
- the script doesn't detect if the output (or error) stream is a terminal. It's probably undesirable to print progress information if the script output is being redirected to a file or another process. You could fix this with a simple
[[ ! -t 1 ]]
check.