Khal a TUI Calendar: Procrastination in Python

khal screenshot

The Bazaar

There are 3 things a digital calendar should do. First and foremost it should track the date accurately. Secondly it should be able to import and export to a standard calendar files . Third it should save and track events. I spent too much time trying to find a calendar that had all these features. At a certain point I should have just bought a paper one, but the buzz of my newly acquired server drove me on to find a calendar application that fulfilled these basic criteria and one more. I wanted a network attached calendar so that I could have my calendar under every circumstance where ever I need it.

If you’ve followed this blog you know about my transition full time to GNU/Linux. I love Linux and everything about it. However sometimes you find yourself lost in the bazaar sampling all of the wares. You smell like a cigarette floating in a serge cola can. The vendor at the last stall beckons you in and their calendars are just like all the rest. Their calendar is beautiful but not functional, like a muddy Persian rug on a yokels porch. You decide that the next day you will head to the larger bazaar with its deep winding alley ways and dark un-trafficed corners.

Curiosity

I really wanted a calendar application that could sync with my self hosted caldav server in order to keep all of my events synchronized across all of my devices. I wanted to have the convenience of cloud services without the abuse of privacy that comes with using proprietary platforms. So I started hosting my own next cloud service on Fedora 30 soon to be 31. I tried almost all of the calendars in the basic Arch software repositories and  was disappointed to find none of them had all of the features I wanted. I’m confident that these projects were still in development, but I wanted something ready made to do what I need. Frustrated I slithered my oily appendages and cat like curiosity to GitHub with a single search phrase and category; calendar in python. Khal came up immediately and in its description it mentioned every feature I wanted.

Eureka

Khal is a TUI calendar application written in python with an ability to sync to caldav servers using a program called vdirsyncer. You can find both of these programs in most distributions software repositories. It takes a couple commands to setup and you have to edit vdirsyncer’s config to communicate with  your server. Once its running its a very efficient system. Khal supports vim keys and integrates well in a workflow that uses many command line applications. If you need help setting things up you can bring up vdirsyncer’s documentation with vdirsyncer --help . Khal has more extensive documentation with a proper manual page that can be brought up with man khal.

My recommendation is to add an alias in your .bashrc or other shell alias ksync='vdirsyncer sync & khal interactive' .This alias makes sure when you use the command ksync your calendar will sync and open up with all the recent events  you’ve added from your other devices. In this fashion your calendar it is always up to date. The logical operator in the command “&” tells the command to run Khal after vdirsyncer regardless of whether or not it was successful. If you want the process to stop if the sync fails add a second “&” to the command.

The Grass is Always Greener

Since I setup this system I have become a big fan of Emacs Org-mode. Org-mode has an agenda which can be edited from Emacs. There are also applications for Emacs which allow you to sync its agenda with caldav servers. There are plenty of reasons I should switch to this workflow but I don’t because Khal follows the UNIX philosophy. It does one thing and one thing well and that’s managing calendars. Meanwhile Emacs does everything which makes it less intuitive.

I’m also aware of calcurse which is a very similar program to  Khal which also has experimental caldav support and an arguably more stylish interface as far as TUI applications go. However I choose to continue using Khal because its written in an accessible language that I can audit and understand and its extensible to other python applications. For instance, Qtile a window manager written in python has a built in widget for khal that displays your next most recent event in the bar and changes colors for alerts.

Not to say that the other calendars GUI options I tried had no merits. I really enjoyed the calendar that the pantheon team has put together it was simply lacking some basic functionality at the time I tried it. The gnome calendar is also really good if you integrate it with the rest of the gnome software suite. XFCE’s Orage calendar was the more traditional and complete out of all the calendars I tried and it can also be synced with vdirsyncer. In the end vdirsyncer is where the magic happens and  it can probably be used in conjunction with most of the less fully feature calendar applications.