Command line calendars with Khal and fastmail

Posted on Tue 04 April 2017 in Linux

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


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

First lets install vdirsyncer with a:

pip install vdirsyncer

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

status_path = "~/.vdirsyncer/status/"

[pair fastmail]
a = "khal"
b = "cal"
collections = ["from a", "from b"]

[storage cal]
type = "caldav"
url = ""
username = ""
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.


Lets install khal first with a:

pip install vdirsyncer

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


path = ~/.vdirsyncer/fastmail/Default
type = discover

path = ~/.vdirsyncer/fastmail/folder_id_1
type = discover

path = ~/.vdirsyncer/fastmail/folder_id_2
type = discover

path = ~/.vdirsyncer/fastmail/folder_id_3
type = discover

path = ~/.vdirsyncer/fastmail/folder_id_3
type = discover

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.


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'