Khal to Org - multiday events

Posted on Feb 18, 2025

Previously I mentioned using Evolution→khal→org-mode to enable me to see my upcoming calendar events in my org-mode agenda. Recently I noticed that multiday events are not handled well - khal is instructed to output the start time for each event, which is always the first day.

Here is an updated script which should be used instead.

#!/usr/bin/env zsh

diary=${HOME}/.emacs.d/diary.org

start=$(date --date='-30days' '+%Y-%m-%d')
end=$(date --date='+30days' '+%Y-%m-%d')

(echo "#+title: Calendar";
 khal list \
      --day-format "DATE={date}" \
      --format "TITLE={title}{repeat-symbol}{alarm-symbol}
TIME={start-end-time-style}
{description}
END" \
      ${start} ${end} | \
     while read i; do
         if [[ ${i} == DATE=* ]]; then
             DATE=${i##DATE=}
         elif [[ ${i} == TITLE=* ]]; then
             TITLE=${i##TITLE=}
         elif [[ ${i} == TIME=* ]]; then
             TIME=${i##TIME=}
         elif [[ ${i} == END ]]; then
             echo "* ${TITLE}"
             echo "<${DATE} ${TIME}>"
             echo "${DESCRIPTION:-}"

             TITLE=""
             TIME=""
             DESCRIPTION=""
         else
             if [[ ${DESCRIPTION} == "" ]]; then
                 DESCRIPTION="$i"
             else
                 DESCRIPTION="${DESCRIPTION}\n$i"
             fi
         fi
     done) > ${diary}