SM Vdirsyncer and Khal


Published on 2020-07-09 #tech

Calendar is a very important tool that most people use regularly to manage their time. I end up setting events for most things. Setting up a easy to use calendar that is synced across all my devices is important. I use Zoho Mail to host my email which also provides me with Calendar support. I will describe my calendar setup on my computers.

I use vdirsyncer to synchronize caldav with local copy of the events and use Khal to read and write them.

All installation commands are shown for Arch Linux, but you should be able to find packages for most Linux distributions.

Install and setup Vdirsyncer

Vdir is a standard format to store calendar as a .ics file in the filesystem. We can use vdirsyncer to events to your CalDAV endpoint.

First install vdirsyncer using the following command.

sudo pacman -Ss calcurse

Once vdirsyncer is installed, you can setup CalDAV synchronization using the following config at ‘$HOME/.config/vdirsyncer/config’

# $HOME/.config/vdirsyncer/config
[general]
status_path = "~/.local/share/vdirsyncer/status/"

[pair default_calendar]
a = "default_calendar_local"
b = "default_calendar_remote"
collections = ["from a", "from b"]
metadata = ["color"]

[storage default_calendar_local]
type="filesystem"
path="~/.local/share/vdirsyncer/calendars/"
fileext = ".ics"

[storage default_calendar_remote]
type="caldav"
url="https://calendar.example.com/caldav/"
username="user@example.com"
password.fetch = ["command", "pass", "show", "user@example.com"]
# password = "Password1234" # If you would like to store password directly.

The config is quite simple, you setup the local and remote location to store calendar. The only information you need is the CalDAV endpoint for your calendar.

Once the config is setup, make vdirsyncer setup the calendar folder structure and test the remote connection.

vdirsyncer discover default_calendar

Once the setup is done, you can sync your calendar using the following command.

Vdirsyncer sync default_calendar

I use cron to regularly sync the local and remote calendars.

Install and setup Khal

Khal is a CLI calendar program. It allows you to read and write to a vdir folder. With vdirsyncer syncing the CalDAV, I use khal to manage my calendar from my terminal. It also enables me to add events from my terminal email client, aerc.

You can install Khal using the following command

sudo pacman -S khal

Once you have installed khal, we can point khal to use the calendar we sync with vdirsyncer. This is a example configuration of the khal config file.

# $HOME/.config/khal/config
[calendars]
[[default]]
path = ~/.local/share/vdirsyncer/calendars/events/
type = calendar
color = dark green

[locale]
timeformat = %I:%M %p
dateformat = %d/%m/%Y
longdateformat = %d/%m/%Y
datetimeformat = %d/%m/%Y %I:%M %p
longdatetimeformat = %d/%m/%Y %I:%M %p

Once the setup is completed, you can access the list of events using either khal list or khal calendar. To create an event, you can use khal new.

If you have an ics calendar file, you can use khal import <ics file>. Or if you need to interactively browse through the calendar, you can use ikhal.