1---
  2title: "Calcurse Notifications"
  3description: "Configuring descriptive and attractive notifications for calcurse"
  4author: Amolith
  5cover: /assets/pngs/calendar.png
  6date: 2020-05-13T22:23:25-04:00
  7draft: false
  8categories:
  9  - Technology
 10tags:
 11  - Calcurse
 12  - CLI
 13  - Notifications
 14  - 100 Days To Offload
 15---
 16
 17I recently started using [calcurse](https://github.com/lfos/calcurse)
 18for my calendar and one of its limitations is good notification support
 19in the generally accepted meaning of the word. The developer has [a
 20different
 21opinion](https://github.com/lfos/calcurse/issues/285#issuecomment-620841221)
 22and that's perfectly alright but traditional notifications are a feature
 23I heavily rely on and calcurse doesn't handle handle them very well; it
 24leaves the user to figure something out on their own. Inspired by [one
 25individual's
 26issue,](https://github.com/lfos/calcurse/issues/286#issue-608118188) I
 27did just that.
 28
 29A quick glance at `man calcurse` reveals this section:
 30
 31``` text
 32-n, --next
 33    Print the first appointment within the next 24 hours. The
 34    printed time is the number of hours and minutes left before
 35    this appointment.
 36```
 37
 38The output of running `calcurse -n`, for me and at the moment, looks
 39like this:
 40
 41``` text
 42$ calcurse -n
 43next appointment:
 44   [17:25] DnD on Mumble
 45```
 46
 47It's all well and good but not really something you'd want in a
 48notification; it needs to be filtered down so it only shows the name of
 49the event, `DnD on Mumble`. To do this, I turned to the man pages of
 50standard CLI utilities `tail` and `cut`. `tail` allows us to filter the
 51output to only the last line[^1] with `tail -1`. `cut` is a little more
 52complicated but will allow us to remove the first few columns of text.
 53`cut -d ' ' -f 5-` is the next snippet in this one-liner. `-d ' '` tells
 54cut to use a single space as the delimiter, `-f` specifies the fields to
 55keep, and `-5` says to use all fields starting with the 5th because
 56there are a few spaces preceding the content we want. Chain all of this
 57mess together with pipes and we get:
 58
 59``` bash
 60calcurse -n | tail -1 | cut -d ' ' -f 5-
 61```
 62
 63Great. Now we need to actually get a notification containing the
 64resulting string. This can be achieved by storing it in a variable then
 65using it with `notify-send`. You likely already have `notify-send`
 66installed if you're using Linux but, if you don't, I would recommend
 67looking around to see what's default and using that instead.
 68
 69``` bash
 70CONT="$(calcurse -n | tail -1 | cut -d ' ' -f 5- -)" && notify-send "Calcurse Event" "$CONT"
 71```
 72
 73Now we're actually getting somewhere. With my setup, the notification
 74looks like this: 
 80
 81It's certainly passable and sufficient for some but I'd like an icon so
 82I can see what the notification is for out of the corner of my eye and
 83decide whether or not to glance over. Thankfully, `notify-send` has this
 84built in with the `-i` flag.
 85
 86``` text
 87-i, --icon=ICON[,ICON...]
 88    Specifies an icon filename or stock icon to display.
 89```
 90
 91Now it's just a matter of figuring out what icon to use. You can
 92certainly pass the path of whatever image you want to it, such as
 93`~/Pictures/calendar-icon.png`, but I want something that fits in with
 94the rest of my icons. These are found in:
 95
 96``` bash
 97/usr/share/icons/<theme>/it/depends/on/theme
 98```
 99
100I use [Suru++ Dark](https://github.com/gusbemacbe/suru-plus-dark) and
101the icon I'm using can be found at:
102
103``` bash
104/usr/share/icons/Suru++-Dark/apps/32@2x/calendar.svg
105```
106
107It's different for Adwaita and all the rest though; you'll have to do
108some digging. It's also worth noting that, if you don't have this theme
109installed on another device, the icon won't show up.
110
111After all that, here's my notification command and a screenshot.
112
113``` bash
114CONT="$(calcurse -n | tail -1 | cut -d ' ' -f 5-)" && notify-send -i /usr/share/icons/Suru++-Dark/apps/32@2x/calendar.svg "Calcurse Event" "$CONT"
115```
116
117
119
120---
121
122This was posted as part of #100DaysToOffload, an awesome idea (dead link to fedi
123post) from [Kev Quirk.](https://kevq.uk/) If you want to participate, just write
124something every day for 100 days and post a link on social media with the
125hashtag!
126
127[^1]: The opposite of `tail` is `head` and allows for exactly the same
128    thing in reverse: `head -1` will return the first line of whatever
129    input it's given.