Darkland | net

Latest Iteration Of Timer Script

Published on 30 December, 2015 by amj
* Updated on 18 October, 2022 by amj

This script calls an external tk file which is linked to at the bottom of the page only because I haven't figured out how to run the python code within the script.
#!/bin/bash
############################
# created on 20151228
# This is a rewrite of a script that
# originally ran for a preset length
# of time. It now runs for an arbitrary
# number de Minutos.
#
# Reference(s):
# http://www.commandlinefu.com/commands/view/7938/countdown-clock
# http://www.shelldorado.com/goodcoding/cmdargs.html
# http://stackoverflow.com/questions/699576/validating-parameters-to-a-bash-script
# http://unix.stackexchange.com/questions/151654/checking-if-an-input-number-is-an-integer
#
############################
##       Change log       ##
############################
##
## 20221018 --amj
## Added Start/Finish time printing.
##
############################
##
helper() {
printf "\nModo de empleo:\n\t Minutos : [entero].\n\n"
}

export PROMPT_COMMAND='echo -ne "\033]0;timer\007"'
i="0"
MIN="0"
if [ $1 ] ; then
	case $1 in
	-h)	helper
	exit 0;;
	esac
fi
while [ $i -lt 1 ]
	do
	read -p "Minutos : " MIN 
		    if [[ $MIN =~ ^[0-9]+$ ]] ; then
	    	    i=$[$i + MIN]
        		else
	        	helper
	    	fi
done
if [ "$1" ] ; then
        case "$1" in
                -a) printf "Start : "; date +%r; printf "End : "; date -d "+$MIN minutes" '+%r'; for ((i=$MIN*60;i>=0;i--));  do echo -ne "\r$(date -d"0+$i sec" +%H:%M:%S)"; sleep 1; done; python2 $HOME/bin/timer2.tk & play -n -c2 -q -t alsa synth sin %0 fade h 0.8 0.25 0.8 repeat 30 & echo -e "\n"
		exit 0;;
                -h)  helper
                     exit 1;;
                 *)  helper
                     exit 1;;
#           --help)  echo >&2 "Modo de empleo: timer [-a]"
#                    exit 1;;
        esac
else
    printf "Start : "; date +%r; printf "End : "; date -d "+$MIN minutes" '+%r'; for ((i=$MIN*60;i>=0;i--));  do echo -ne "\r$(date -d"0+$i sec" +%H:%M:%S)"; sleep 1; done; python2 $HOME/bin/timer2.tk & echo -e "\n" ;date +%r 
fi
exit
External tk file: timer2.tk(Written for python2)
Back