Just some light shell scripting today!

Pomodoro timers are a big thing in ADHD circles because they help with focusing on a task and keeping track of time, two things that many of us with ADHD find challenging. Physical timers are nice (some of them are really flashy) but not always convenient, especially if you don’t always work at the same place. I travel a lot, for example, or sometimes find myself working somewhere other than my home office, and carrying a physical timer around or having it take up space doesn’t always work well for me.

I have been doing things like just using the timer on my phone or watch for this, but yesterday YouTube recommended a video produced by bashbunni talking about their custom CLI timer. It’s a neat combination of CLI tools into a couple handy shell aliases that give a count-down with progress bar, and a desktop notification!

The aliases depend on two external tools, one of which is MacOS-specific. The first is Timer by Carlos Alexandro Becker, which is a little Go app that basically acts like sleep but with a progress bar and timer. The second is terminal-notifier by Julien Blanchard, which is a Mac-specific tool for sending system notifications from the command-line. Bashbunni also has a Linux-compatible version of their timer, linked from their video, which doesn’t depend on the MacOS terminal-notifier.

This morning I took a few minutes to bodge together my own version. For the moment it’s mostly a simple re-write of bashbunni’s, but I made a few small changes. First, I pulled out all the variables into… variables! I also dropped the use of the terminal-notifier‘s -appIcon parameter, because that is currently broken (it depends on a private call in a library that has presumably changed or gone away). I also set it up so that the current time will be included in the notification, so that if I’m away from my desk I can quickly see how long ago the notification fired. My new version looks like this:

if [[ $OSTYPE =~ 'darwin.*' ]]; then
    POMO_WORKMSG="Work timer is up! Take a break."
    POMO_RESTMSG="Break is over!  Time to get back to work."
    POMO_OPTIONS=(-title Pomodoro -sound ${POMO_SOUND})
    POMO_DATE=(date "+%H:%M")
    alias work="timer ${POMO_WORKTIME} && terminal-notifier ${POMO_OPTIONS}\
        -message '\[$(${POMO_DATE})] ${POMO_WORKMSG}'"
    alias rest="timer ${POMO_RESTTIME} && terminal-notifier ${POMO_OPTIONS}\
        -message '\[$(${POMO_DATE})] ${POMO_RESTMSG}'"

You’ll notice the whole thing is also wrapped in an if block. This is because I use the same .zshrc on several different platforms, and I don’t want something that will only work on MacOS polluting my config elsewhere.


This is also available in a gist, and I plan to (try to remember to) keep that updated when I make changes.

Feel free to copy this if you want. If you are a bash user, you’ll need to rework things like the zsh list syntax for ${POMO_OPTIONS} and the date command.

I have it in mind to generalize the aliases a bit, in particular for different types of work that I expect to spend longer or shorter periods of time on. For example, I’d like it to take options so that I can incorporate something like CGP Grey‘s “units of work” idea, and set a timer for a specific number of units, rather than a time. I also use pomodoros to put a limit on longer breaks—like when I’m playing a video game—to remind me to either get back to work (on a work day) or just go do something else for a while, and so it needs to be able to accommodate that kind of reminder.

#100DaysToOffload article 2 of 100