Sway Pomodoro Timer

last updated 2020-11-28 09:27:50 by Simon Vandevelde

This guide briefly goes over how to get a working pomodoro timer on Sway, the tiling Wayland compositor and my preferred way of working on Linux (it should also work on i3).

One of the most important aspects of life, especially now that a lot of us are experiencing the (dis)pleasures of working at home, is finding a good balance between work and relaxation. Something that helps me greatly in achieving this on a day-to-day basis is the concept of the pomodoro technique: work in intervals (for me 35 mins works best) and take a short break of about 5 minutes in between them. After four work intervals, take a longer break of e.g. 15 minutes.

To aid in this technique, there exist the so-called pomodoro-timers: simple timers that keep track of how long you've been working and how many intervals you've done so far. There exist many timers that work on Linux, but only a few of them are elegant or minimal enough. In this guide, we will be "integrating" James Spencer's pomo.sh script into our sway, by starting it on boot, allowing it to sent notifications and by adding it to the statusbar.

Set up the script

Start by simply cloning the pomo.sh repository. Then we make sure that it can be executed, and we move it to a folder on our PATH. This allows us to call the script from anywhere on the command line.
    $ git clone https://github.com/jsspencer/pomo && cd pomo
    $ chmod +x pomo.sh  # Make sure the file is executable.
    $ mv pomo.sh /usr/local/bin/pomo.sh  # You might need sudo.

That's already 30% of the work done. You should now be able to run the pomo.sh command in every terminal. Try and see if pomo.sh start and pomo.sh clock work. By editing the pomo.sh file, you can set up things like work duration and extended pause frequency.

Basically, we now want to make sure that sway runs those commands for us. If we want notifications from the script, we also need to run pomo.sh notify, have libnotify installed and have a notification daemon such as mako.

Start on boot and allow notifictations

To start the script on boot, we add it to our sway config. This is located in ~/.config/sway/config. Edit it to contain the following anywhere in the file:

    # Set pomodoro timer
    exec pomodoro start # Automatically start timer.
    exec pomodoro notify # To enable notifications.

Add it to the statusbar

Now that the pomodoro runs, it would be ideal to also see how long until the next work/pause block. Luckily for us, this is also simple. This part of the guide assumes that you have never edited your statusbar before. If you have, you probably know what to do.

You might have noticed that in the sway config file there was a code block bar. In this block, the status_command is set with the date. We are going to create our own status command to display the pomodoro timer on top of the date. Create a new file ~/.config/sway/statusbar.sh and type in the following but remove the spaces after the dollars.

    # A custom sway bar to show date and pomodoro duration.
    date_formatted=$(date "+%a %F %H:%M")
    pomodoro_time=$(pomodoro clock)
    echo $ pomodoro_time '|' $ date_formatted

Now we make sure that it is executable, and we test to see if it works.

    $ chmod +x ~/.config/sway/statusbar.sh
    $ bash +x ~/.config/sway/statusbar.sh

This should output the remaining time on the timer, followed by the date. If this works, we can add it to our sway config. Find the bar segment and change the status_command as follows.

    status_command while ~/.config/sway/status.sh; do sleep 1; done

This will update the statusbar once every second with a new timer duration and the date.

And that's it! You now have a working, minimal pomodoro timer on Sway.