I made a small countdown script for the shell. It goes as follows:
This file contains 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 | |
# USAGE | |
# ./countdown <num of seconds> <msg> | |
# eg: | |
# ./countdown 300 Time to rock! | |
date1=$((`date +%s` + $1)); | |
shift | |
while [ "$date1" -ne `date +%s` ]; do | |
echo -ne "$(date --date @$(($date1 - `date +%s` - 19800 )) +%H:%M:%S)\r"; | |
done | |
notify-send 'Timer finished' "$*" | |
zenity --info --title "Timer finished" --text "$*" |
Some tricks used in the script include:
echo -ne "blah blah \r"
was used to write in the same line over and over- That 19800 is the time difference from GMT 0.0 in seconds. In Sri Lanka, it’s 5.30 hrs. Yes, we’re dealing with epoch time here, but still trying to figure out why we need to offset the time difference. 😕
notify-send
sends a desktop notificationzenity --info
pops up a message box
You can also add a sound to play with mplayer
.