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 after start_spinner (or some operation completes very quickly), the output gets a bit messed up. This is because stop_spinner doesn't wait for the spinner job to terminate before writing to the terminal. This can be accomplished with a simple wait ${_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.
Thanks! This script inspired me to build a progress spinner for some scripts I'm writing.
I have found a few issues though:
stop_spinneris called immediately afterstart_spinner(or some operation completes very quickly), the output gets a bit messed up. This is becausestop_spinnerdoesn't wait for the spinner job to terminate before writing to the terminal. This can be accomplished with a simplewait ${_sp_pid}.[[ ! -t 1 ]]check.