Command line calendars with Khal and fastmail

Shane Dowling
Apr 4, 2017 · 2 min read

Recently I’ve been on a bit of a command line kick and I started using khal to render my calendar agenda locally.

All of the codebases used are python based so before I start I’ve created a virtualenv so as not to pollute my OS.

mkvirtualenv khal
workon khal

Vdirsyncer

Firstly we need to setup Vdirsyncer, which is used to actually download your caldav entries to a local folder which khal then reads from.

pip install vdirsyncer

Then to configure it create a file in ~/.vdirsyncer/config and adding these contents, replacing the username/password with your own.

[general]
status_path = “~/.vdirsyncer/status/”
[pair fastmail]
a = “khal”
b = “cal”
collections = [“from a”, “from b”]
[storage cal]
type = “caldav”
url = “https://caldav.messagingengine.com/"
username = “user@fastmail.fm”
password = “ONE_TIME_PASSWORD”
read_only = “true”
[storage khal]
type = “filesystem”
path = “~/.vdirsyncer/fastmail”
fileext = “.ics”
#encoding = “utf-8”
#post_hook = null

Then run an initial vdirsyncer command, this will create a bunch of folders under ~/.vdirsyncer/fastmail, each of these represents each of the calendars you have in fastmail.

Khal

pip install khal

Now to configure khal we create this file in ~/.config/khal/config with the contents, replace the folder_id_* with the actual foldernames in ~/.vdirsyncer/fastmail

[calendars][[default]]
path = ~/.vdirsyncer/fastmail/Default
type = discover
[[travel]]
path = ~/.vdirsyncer/fastmail/folder_id_1
type = discover
[[events]]
path = ~/.vdirsyncer/fastmail/folder_id_2
type = discover
[[admin]]
path = ~/.vdirsyncer/fastmail/folder_id_3
type = discover
[[birthdays]]
path = ~/.vdirsyncer/fastmail/folder_id_3
type = discover
[locale]
timeformat = %H:%M
dateformat = %d/%m/%Y
longdateformat = %d/%m/%Y
datetimeformat = %d/%m/%Y %H:%M
longdatetimeformat = %d/%m/%Y %H:%M

Now if you run khal you should get a nice calendar view with an agenda next to it.

Aliases

To keep things simple I created an alias that allows me to pop into this virtualenv, sync my calendars and display khal whenever I need my calendars displayed.

alias khal=’workon khal && vdirsyncer sync && khal’

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store