Last active
December 5, 2015 08:05
-
-
Save abcarroll/67e6479e4f73729c21cf to your computer and use it in GitHub Desktop.
Counts down a long sleep
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Written by A.B. Carroll <[email protected]> | |
# Use as: | |
# sleepcountdown HOUR MIN SEC "Optional Prefix" | |
# Example: | |
# sleepcountdown 00 00 10 "Time until next run: " | |
# echo "Done with first countdown!" | |
# sleepcountdown 01 00 05 "Time until next run: " | |
# echo "Done with second countdown!" | |
sleepcountdown(){ | |
hr=$1 | |
min=$2 | |
sec=$3 | |
if [ -z "$4" ] | |
then | |
prefix="" | |
else | |
prefix="$4" | |
fi | |
while [ $hr -ge 0 ]; do | |
while [ $min -ge 0 ]; do | |
while [ $sec -ge 0 ]; do | |
printf "%s%02d:%02d:%02d\33[0K" "${prefix}" "${hr}" "${min}" "${sec}" | |
sec=$((sec-1)) | |
sleep 1 | |
printf "\r" | |
done | |
sec=59 | |
min=$((min-1)) | |
done | |
min=59 | |
hr=$((hr-1)) | |
done | |
printf "\n" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment