Skip to content

Instantly share code, notes, and snippets.

@abcarroll
Created September 4, 2015 08:37
Show Gist options
  • Save abcarroll/5a55225e24d9225a5742 to your computer and use it in GitHub Desktop.
Save abcarroll/5a55225e24d9225a5742 to your computer and use it in GitHub Desktop.
Countdown with
countsheep(){
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
echo -ne "${prefix}$(printf %02d "$hr"):$(printf %02d "$min"):$(printf %02d "$sec")\033[0K"
sec=$((sec-1))
sleep 1
echo -ne "\r"
done
sec=59
min=$((min-1))
done
hr=$((hr-1))
done
}
# Usage:
# coutnsheep h m s "Prefix if desired"
# example:
# countsheep 1 30 0 "Time until next action: "
# will print:
# Time Until next action: 01:30:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment