Reading Time: 3 minutes | Published: 2020-05-13 | Last Edited: 2021-11-10
I recently started using calcurse for my calendar and one of its limitations is good notification support in the generally accepted meaning of the word. The developer has a different opinion and that’s perfectly alright but traditional notifications are a feature I heavily rely on and calcurse doesn’t handle handle them very well; it leaves the user to figure something out on their own. Inspired by one individual’s issue, I did just that.
A quick glance at
man calcurse reveals this section:
-n, --next Print the first appointment within the next 24 hours. The printed time is the number of hours and minutes left before this appointment.
The output of running
calcurse -n, for me and at the moment, looks
$ calcurse -n next appointment: [17:25] DnD on Mumble
It’s all well and good but not really something you’d want in a
notification; it needs to be filtered down so it only shows the name of
DnD on Mumble. To do this, I turned to the man pages of
standard CLI utilities
tail allows us to filter the
output to only the last line1 with
cut is a little more
complicated but will allow us to remove the first few columns of text.
cut -d ' ' -f 5- is the next snippet in this one-liner.
-d ' ' tells
cut to use a single space as the delimiter,
-f specifies the fields to
-5 says to use all fields starting with the 5th because
there are a few spaces preceding the content we want. Chain all of this
mess together with pipes and we get:
calcurse -n | tail -1 | cut -d ' ' -f 5-
Great. Now we need to actually get a notification containing the
resulting string. This can be achieved by storing it in a variable then
using it with
notify-send. You likely already have
installed if you’re using Linux but, if you don’t, I would recommend
looking around to see what’s default and using that instead.
CONT="$(calcurse -n | tail -1 | cut -d ' ' -f 5- -)" && notify-send "Calcurse Event" "$CONT"
Now we’re actually getting somewhere. With my setup, the notification looks like this:
It’s certainly passable and sufficient for some but I’d like an icon so
I can see what the notification is for out of the corner of my eye and
decide whether or not to glance over. Thankfully,
notify-send has this
built in with the
-i, --icon=ICON[,ICON...] Specifies an icon filename or stock icon to display.
Now it’s just a matter of figuring out what icon to use. You can
certainly pass the path of whatever image you want to it, such as
~/Pictures/calendar-icon.png, but I want something that fits in with
the rest of my icons. These are found in:
I use Suru++ Dark and the icon I’m using can be found at:
It’s different for Adwaita and all the rest though; you’ll have to do some digging. It’s also worth noting that, if you don’t have this theme installed on another device, the icon won’t show up.
After all that, here’s my notification command and a screenshot.
CONT="$(calcurse -n | tail -1 | cut -d ' ' -f 5-)" && notify-send -i /usr/share/icons/Suru++-Dark/apps/32@2x/calendar.svg "Calcurse Event" "$CONT"
The opposite of
headand allows for exactly the same thing in reverse:
head -1will return the first line of whatever input it’s given. ↩︎