diff --git a/really-long-command b/really-long-command index e583ecf..619e661 100755 --- a/really-long-command +++ b/really-long-command @@ -1,5 +1,6 @@ #! /usr/bin/env bash -sleep 4 -echo "Ende langes Kommando" - +for i in {1..4}; do + echo "[$$] finished ${i}/4 ticks" + sleep 1 +done diff --git a/spinner.sh b/spinner.sh index 2af47b4..7698148 100755 --- a/spinner.sh +++ b/spinner.sh @@ -1,10 +1,38 @@ #! /usr/bin/bash +spinner_pid= -for c in '/' '|' '\' '-'; do - printf "\r%s" "${c}" - sleep 1 -done +spinner() { + local chars=('\' '|' '/' '-') + local c -echo -echo 'done' + while true; do + for c in ${chars[@]}; do + printf "<%s>\r" "${c}" + sleep .2 + done + done +} + +cleanup() { + echo "done" + if [[ -n ${spinner_pid} ]]; then + kill "${spinner_pid}" + fi + echo "[$$] finished spinner" +} + +main() { + trap cleanup EXIT + + spinner & + spinner_pid=$! + + if (( $# == 0)); then + echo "Usage: spinner " + return 1 + fi + "$@" +} + +main "$@"