# How to create your own Pomodoro timer for Ubuntu using Bash

I recently discovered a small program for Ubuntu called notify-send (opens new window) . You can use it to create desktop notifications. I've been using it to send myself a notification after a long-running script has finished. Like this:

./long-running-script.sh && notify-send "The long script is done"
1

I figured it could also be useful for creating my own pomodoro-style timer.

Ubuntu has another command, sleep, that we can use to set up a timer. You can tell sleep how long to sleep for by passing it an amount of seconds (the default), minutes (with the suffix m), hours or even days.

Let's say you want focus on a single task for 40 minutes. You run sleep with an argument of 45m and send yourself a notification when it's done using notify-send:

sleep 45m && notify-send "Well done\! Time to rest"
1

When you use the Pomodoro technique (opens new window), you would usually work in intervals of 25 minutes with short breaks of 5 minutes in between. To repeat these intervals, we can use a Bash while-loop:

while true
do
	sleep 45m
	notify-send "Time to rest\!"
	sleep 5m
	notify-send "Time to get back to work\!"
done
1
2
3
4
5
6
7

We can simply use Control-C to stop the loop once we feel like a longer break.

Personally I prefer working in intervals of 40 minutes with 10 minute breaks in between. And I take longer breaks when I feel like I need it. However, if you want to follow the Pomodoro technique to the 'T', you can use a for-loop to create four iterations of work and short breaks, followed by a long break:

while true
do
  for i in {1..4}
  do
	  sleep 25m
	  notify-send "Time to take a short break"
	  sleep 5m
	  notify-send "Time to get back to work"
  done
  notify-send "Time for a long break"
  sleep 15m
  notify-send "Time to work"
done
1
2
3
4
5
6
7
8
9
10
11
12
13

To make it easy to use, we can save our code in a script at /usr/local/bin/pomodoro. After running chmod +x on the file, we will be able run pomodoro from any directory to start the timer!

You can download my script here (opens new window). Feel free to modify it to your needs. I think a cool next step would be to add a visual count-down timer!

Newsletter

If you'd like to subscribe to my blog, please enter your details below. You can unsubscribe at any time.

Powered by Buttondown.

Last Updated: 11/20/2023, 10:04:51 AM