Skip to content

Instantly share code, notes, and snippets.

@dphov
Created December 24, 2017 15:26
Show Gist options
  • Save dphov/21b5fc7bbc16e9532a97c9790aad00d4 to your computer and use it in GitHub Desktop.
Save dphov/21b5fc7bbc16e9532a97c9790aad00d4 to your computer and use it in GitHub Desktop.
POSIX shell compatible countdown timer. Credits to @cfajohnson
countdown()
(
IFS=:
set -- $*
secs=$(( ${1#0} * 3600 + ${2#0} * 60 + ${3#0} ))
while [ $secs -gt 0 ]
do
sleep 1 &
printf "\r%02d:%02d:%02d" $((secs/3600)) $(( (secs/60)%60)) $((secs%60))
secs=$(( $secs - 1 ))
wait
done
echo
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment