Last active
October 20, 2024 04:43
-
-
Save tir38/5855000 to your computer and use it in GitHub Desktop.
in-terminal timer shell script
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
# script to create timer in terminal | |
# Jason Atwood | |
# 2013/6/22 | |
#!/bin/sh | |
# start up | |
echo "starting timer script ..." | |
sleep 1 # seconds | |
# get input from user | |
read -p "Timer for how many minutes?" -e DURATION | |
DURATION=$(( $DURATION*60 )) # convert minutes to seconds | |
# get start time | |
START=$(date +%s) | |
# infinite loop | |
while [ -1 ]; do | |
clear # clear window | |
# do math | |
NOW=$(date +%s) # get time now in seconds | |
DIF=$(( $NOW-$START )) # compute diff in seconds | |
ELAPSE=$(( $DURATION-$DIF )) # compute elapsed time in seconds | |
MINS=$(( $ELAPSE/60 )) # convert to minutes... (dumps remainder from division) | |
SECS=$(( $ELAPSE - ($MINS*60) )) # ... and seconds | |
# conditional | |
if [ $MINS == 0 ] && [ $SECS == 0 ] # if mins = 0 and secs = 0 (i.e. if time expired) | |
then # blink screen | |
for i in `seq 1 180`; # for i = 1:180 (i.e. 180 seconds) | |
do | |
clear # flash on | |
setterm -term linux -back red -fore white # use setterm to change background color | |
echo "00:00 " # extra tabs for visibiltiy | |
sleep 0.5 | |
clear # flash off | |
setterm -term linux -default # clear setterm changes from above | |
echo "00:00" # (i.e. go back to white text on black background) | |
sleep 0.5 | |
done # end for loop | |
break # end script | |
else # else, time is not expired | |
echo "$MINS:$SECS" # display time | |
sleep 1 # sleep 1 second | |
fi # end if | |
done # end while loop |
Can you add options to the end time to play music? PLEASE.
You can make your own beep in linux with
( speaker-test -t sine -f 400 -l 1 >/dev/null & sleep .3 && kill -9 $! );( speaker-test -t sine -f 500 -l 1 >/dev/null & sleep .3 && kill -9 $! );( speaker-test -t sine -f 300 -l 1 >/dev/null & sleep .3 && kill -9 $! )
This does a Do DOO doo sound.
Replace lines 31 to 43 with it
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Worked immediately on OSX in iTerm. Thank you!