Simple Pomodoro Timer Bash Script


This is a simple timer script, implementing the pomodoro technique for time management. There are tons out there already but I didn’t like how they auto- started breaks. And most lacked shortcut abilities, so that was a dealbreaker.

  • The script takes the number of seconds as an argument. e.g. timer.sh 300 for 5 minutes.
  • It changes the window title so you can see the countdown in the window bar.
  • Plays a sound when it starts and when it ends

I’m using it bound to keyboard shortcuts, so I can use hotkey-1 for 5 minutes, hotkey-3 for 15 minutes, etc.

You’ll need to first install these guys:

sudo apt install figlet vorbis-tools

And then copy and paste this into timer.sh:

#!/bin/bash
if [ "$1" = "stop" ]; then
	echo Stopping timer.sh
	killall $(basename $0)
	exit 1
fi
if [ -z "$1" ]; then
	echo "Must give a number for the countdown (in seconds)"
	echo "   e.g.$0 300 # five minute countdown"
	exit 1
fi
num=$1
# thanks https://stackoverflow.com/questions/12199631/convert-seconds-to-hours-minutes-seconds
convertsecs() {
	((h=${1}/3600))
	((m=(${1}%3600)/60))
	((s=${1}%60))
	if [ "$1" -gt 3600 ]; then
		printf "%02d:%02d:%02d" $h $m $s
	else
		printf "%01d:%02d" $m $s
	fi
}
wintitle () {
	echo -e '\033]2;'$1 - $0'\007'
}
funk () {
	printf "\033c"
	figlet -cf big "$1"
}
origconverted=$(convertsecs $num)
countdown () {
	convertednum=$(convertsecs $num)
	disp="$convertednum / $origconverted"
	wintitle "$disp"
	funk "$disp"
	sleep 1
	let num=$num-1
}
soundoff () {
	ogg123 /usr/share/sounds/LinuxMint/stereo/$1 -q &
}
soundoff window-slide.ogg
while [ $num -gt -1 ]; do
	countdown
done
soundoff phone-incoming-call.ogg

And the recommended way to launch this (using a keyboard shortcut or whatever) is:

gnome-terminal -- bash -c "timer.sh 300; exec bash"