Calendar sync via command line

I’m currently revising how I’m using my tools and try to removed distractions. One significant source of distraction is Thunderbird because whenever I want to create an appointment or want to check my upcoming events, I instead open the Mail view first and start to read mails. The solution is to move my calendar into a separated application. One thing I favour is having the tool for the command line.

After some searching, the following tools can be found: khal. Calendar on the console

There is another tool pcal that might could fit, however, it does not support calendar sync like a owncloud.

To install khal you could get it via pip, but also For the Installation via archlinux:

pip install khal

or get the

pip install git+git://

or from archlinux:

pacman -S khal

The next step is to define the endpoints for the configuration. This file is located to in .config/khal like this:


    path = ~/.calendars/home/
    color = green

    path = ~/.calendars/work/
    readonly = True

However, this

There is a good documenation about this from Eric Scheibler. He provides an example for fetchin to have a better basic:

mkdir ~/.config/khal
wget -O ~/.config/khal/khal.conf

I’ve updated it reflect my configuration a bit:

path = ~/.calendars/*
type = discover
color = dark green

local_timezone= Europe/Berlin
default_timezone= Europe/Berlin
timeformat= %H:%M
dateformat= %d.%m.
longdateformat= %d.%m.%Y
datetimeformat= %d.%m. %H:%M
longdatetimeformat= %d.%m.%Y %H:%M

default_calendar = personal
timedelta = 7d # the default timedelta that list uses
highlight_event_days = True


What your doing here is point out to folder where the calendars is located for display. But how does the calendar get there? For this we have another tool, called vdirsync. You have to install it, similar like khal, but I keep the installation via pacman.

pacman -S vdirsyncer

Again I’m using the example from Eric Scheibler with vdirsync. However it’s a little bit out-dated. I had to tinker around a bit to get it running. The essential is the

status_path = "~/.vdirsyncer/status/"

[pair calendar]
a = "calendar_local"
b = "calendar_remote"
collections = ["university","personal", "contact_birthdays", "prüfung" ]
conflict_resolution = "b wins"

[storage calendar_local]
type = "filesystem"
path = "~/.calendars/"
fileext = ".ics"

[storage calendar_remote]
type = "caldav"
url = ""
#auth = "digest"
#verify = /etc/ssl/local/
username = "akendo"
password = "<reacted>"
start_date = " - timedelta(days=365)"
end_date = " + timedelta(days=365)"

One issue that remains in here is that the password is stored in plaintext. But I think Thunderbird does essentially the same. Here two things to consider: the start_date and end_date are time frame how old an event in your calendar should be synced. In this example, I get all events that are older one year. collections defines the calendar that should be synchronised. Important is the keyword for conflict_resolution. In case an event exists remote and locally, here we set the default policy to handle the conflict. On our instance, we do not use the local change.

Once the configuration is completed we try to run vdirsyncer discover calendar to see what type of calender are present on our URL endpoint. At first, it take some attempts to get this going. When you need to reset the state, you can remove the folder .calendars/ and .vdirsyncer/ to reset to a clean state.

When the right calendars are discovered to your locale system you can synchronise the events of it via: vdirsyncer sync

Keeping it syncing

One down side so far is that the vdirsyncer sync is one time. You have to manual sync it from time to time. You can create this via cronjob. That’s all for today.

best regards, akendo