Hey folks!

For those of you looking for a lovely CLI tool to show your upcoming calendar items on Google Calendar, I can wholly recommend the tool gcalcli (AUR). Setup is pretty easy, and it lets you add stuff to your calendar, and display a few different formats. Personally, I quite like the agenda format, and wanted to show it every time I opened my terminal to help me remember about upcoming events and appointments.

A screenshot of my terminal, showing off the agenda output of gcalcli on a fresh start

As many of you may know, adding commands to your .bashrc or .zshrc will output them, however I don't recommend having gcalcli being called directly, as it can take 15 - 30 seconds on my system to return, making getting going in your terminal rather annoying.

How do we solve this, then? How do we make it so we can have an updating agenda and keep the terminal startup snappy?

How about another.... SystemD Timer!

That's right, folks, we're going to use systemd timers to have an excuse to learn how to use systemd more!

We're going to be creating two files in ~/.config/systemd/user/ -- agenda.service and agenda.timer and one script in the homedir called agendaupdate.sh, which makes it easier to customize the output without needing to reload the service each time you make changes.

Please remember that this is configured for my setup, you may need to modify. Don't just copypaste my stuff, blindly copypasting is dangerous!

agenda.service

[Unit]
Description=Agenda Population

[Service]
Type=oneshot
ExecStart=/home/clarjon1/agendaupdate.sh

agenda.timer

[Unit]
Description=Agenda Population timer

[Timer]
OnBootSec=4min
OnUnitActiveSec=15min

[Install]
WantedBy=timers.target

The timer section on this will wait 4 minutes until after system is booted, which should be enough time for me to be logged in and have network up and running. I've not added a check or dependency on the network being up yet -- once I get around to it I'll update this post. It then triggers once every 15 minutes thereafter, so anything new popping up on my agenda will show up within a quarter of an hour.

agendaupdate.sh

#!/bin/sh
/usr/bin/gcalcli agenda > /home/clarjon1/.agenda.txt

Once we've added these files, you'll need to run systemctl --user start agenda.timer ; systemctl --user enable agenda.timer to get it up and running for this session, and enable it for future login sessions.

You can use the command systemctl --user status agenda.service to see if it's up and running properly, and how long until the next trigger is. It should look something like this:

A screenshot of the output of the systemd status for the timer

The .timer file will call the .service file which calls the script which plops the output of the gcalcli into a text file. After the timer has triggered, use cat ~/.agenda.txt to check on the contents of the file, make sure that the output is what we're wanting.

Then we add cat ~/.agenda.txt to our .bashrc. or .zshrc or the rc of whatever shell you use to output it. Don't know what shell you're using? Run echo $SHELL to see what's loaded!

Now when you open a new terminal, upcoming appointments on your calendar will be front and center, with no real noticable delay with opening the shell!

Next Post Previous Post