secluded/content/posts/calcurse-notifications.md

131 lines
4.8 KiB
Markdown
Raw Normal View History

2021-01-11 17:34:38 +00:00
---
title: "Calcurse Notifications"
description: "Configuring descriptive and attractive notifications for calcurse"
2021-11-10 08:07:08 +00:00
author: Amolith
2021-01-11 17:34:38 +00:00
cover: /assets/pngs/calendar.png
date: 2020-05-13T22:23:25-04:00
categories:
- Technology
tags:
- Calcurse
- CLI
- Notifications
- 100 Days To Offload
---
2021-06-26 20:51:30 +00:00
I recently started using [calcurse](https://github.com/lfos/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](https://github.com/lfos/calcurse/issues/285#issuecomment-620841221)
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,](https://github.com/lfos/calcurse/issues/286#issue-608118188) I
did just that.
2021-01-11 17:34:38 +00:00
A quick glance at `man calcurse` reveals this section:
2021-06-26 20:51:30 +00:00
``` text
2021-01-11 17:34:38 +00:00
-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.
```
2021-06-26 20:51:30 +00:00
The output of running `calcurse -n`, for me and at the moment, looks
like this:
``` text
2021-11-10 08:07:08 +00:00
$ calcurse -n
2021-01-11 17:34:38 +00:00
next appointment:
[17:25] DnD on Mumble
```
2021-06-26 20:51:30 +00:00
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
the event, `DnD on Mumble`. To do this, I turned to the man pages of
standard CLI utilities `tail` and `cut`. `tail` allows us to filter the
output to only the last line[^1] with `tail -1`. `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
keep, and `-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:
``` bash
2021-01-11 17:34:38 +00:00
calcurse -n | tail -1 | cut -d ' ' -f 5-
```
2021-06-26 20:51:30 +00:00
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 `notify-send`
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.
``` bash
2021-01-11 17:34:38 +00:00
CONT="$(calcurse -n | tail -1 | cut -d ' ' -f 5- -)" && notify-send "Calcurse Event" "$CONT"
```
2021-06-26 20:51:30 +00:00
Now we're actually getting somewhere. With my setup, the notification
looks like this: ![It's a screenshot of my desktop with a notification
in the top right corner. The title is "Calcurse Event" and the text
below is "DnD on Mumble". Surrounding the text is a solid border. Its
position and the border are all that designate it as a notification: the
background and text colour match the rest of my desktop which is themed
with the base16-unikitty-dark scheme](/assets/jpgs/notification.jpg)
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` flag.
2021-01-11 17:34:38 +00:00
2021-06-26 20:51:30 +00:00
``` text
2021-01-11 17:34:38 +00:00
-i, --icon=ICON[,ICON...]
Specifies an icon filename or stock icon to display.
```
2021-06-26 20:51:30 +00:00
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:
``` bash
2021-01-11 17:34:38 +00:00
/usr/share/icons/<theme>/it/depends/on/theme
```
2021-06-26 20:51:30 +00:00
I use [Suru++ Dark](https://github.com/gusbemacbe/suru-plus-dark) and
the icon I'm using can be found at:
``` bash
2021-01-11 17:34:38 +00:00
/usr/share/icons/Suru++-Dark/apps/32@2x/calendar.svg
```
2021-06-26 20:51:30 +00:00
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.
2021-01-11 17:34:38 +00:00
After all that, here's my notification command and a screenshot.
2021-06-26 20:51:30 +00:00
``` bash
2021-01-11 17:34:38 +00:00
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"
```
2021-06-26 20:51:30 +00:00
![This is a screenshot like the last one but with an attractive icon to
the left of the text](/assets/jpgs/notification-icon.jpg)
2021-01-11 17:34:38 +00:00
---
2021-06-26 20:51:30 +00:00
This was posted as part of
[#100DaysToOffload,](https://100daystooffload.com/) an [awesome
idea](https://fosstodon.org/@kev/104053977554016690) from [Kev
Quirk.](https://kevq.uk/) If you want to participate, just write
something every day for 100 days and post a link on social media with
the hashtag!
[^1]: The opposite of `tail` is `head` and allows for exactly the same
thing in reverse: `head -1` will return the first line of whatever
input it's given.