aboutsummaryrefslogtreecommitdiff
path: root/home/dot_config/vdirsyncer
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2026-08-02 14:48:29 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2026-08-02 14:48:29 +0200
commite43eb1177872f52e949fb5f0f93396ed94b0d093 (patch)
tree78b73af6a989fa2996d71b112e161b70d35081ef /home/dot_config/vdirsyncer
parent2f14a896e4b897bd747c24d7ad8e9e7bb3237d03 (diff)
move to chezmoi
Diffstat (limited to 'home/dot_config/vdirsyncer')
-rw-r--r--home/dot_config/vdirsyncer/config.sh.example31
-rw-r--r--home/dot_config/vdirsyncer/executable_config_gen111
2 files changed, 142 insertions, 0 deletions
diff --git a/home/dot_config/vdirsyncer/config.sh.example b/home/dot_config/vdirsyncer/config.sh.example
new file mode 100644
index 0000000..0c7d81a
--- /dev/null
+++ b/home/dot_config/vdirsyncer/config.sh.example
@@ -0,0 +1,31 @@
+#!/bin/sh
+# this file is included from .config/vdirsyncer/config_gen and
+# .config/khal/config_gen. The shims for `khal` and `vdirsyncer` automatically
+# run these scripts to update the configuration files. Note that you do still
+# need to set up a synchronization mechanism (e.g. systemd timer for running
+# `vdirsyncer sync`)
+
+# uncomment to convert true color calendar color (#RRGGBB) into 16-color (ANSI)
+# codes
+# export QUANTIZE_COLOR=y
+
+### CalDAV example
+# NOTE: color and display name are automatically downloaded from the server,
+# and can not be set manually
+caldav 'https://dav.example.com' 'username' "$(pass www/dav.example.com/username)"
+# `caldav` only syncs calendar items. you can replace `caldav` with `carddav`
+# to only sync address books, or replace it with `dav` to sync both
+
+### Web calendar example
+# NOTE: url should start with http(s)://, not webcal://
+ical 'https://example.com/calendar-1.ics'
+# COLOR and NAME can be overridden for ical URLs:
+COLOR='light magenta' NAME='Calendar 2' ical 'https://example.com/calendar-2.ics'
+# Comment a line to disable the calendar (temporarily)
+#ical 'https://example.com/calendar-3.ics'
+# iCal URL that requires HTTP authentication:
+ical 'https://example.com/calendar-1.ics' 'username' 'password'
+
+# Keep in mind that this file is just a POSIX sh script, and you can use
+# environment variables, control flow, etc.
+
diff --git a/home/dot_config/vdirsyncer/executable_config_gen b/home/dot_config/vdirsyncer/executable_config_gen
new file mode 100644
index 0000000..bf5d570
--- /dev/null
+++ b/home/dot_config/vdirsyncer/executable_config_gen
@@ -0,0 +1,111 @@
+#!/bin/sh
+CONFIG_FILE="$(dirname "$0")/config.sh"
+[ ! -e "$CONFIG_FILE" ] && {
+ echo "please create $CONFIG_FILE"
+ exit 1
+}
+
+VDIRSYNCER_PREFIX="$XDG_DATA_HOME/vdirsyncer"
+VDIRSYNCER_STATUS_PATH="$VDIRSYNCER_PREFIX/status"
+
+# generate a valid storage/pair name from an invalid one
+safeify() { echo "$1" | sha1sum | cut -c1-40 ; }
+# safeify() { echo "$1" | tr -c '0-9A-Za-z' '_' | sed 's/_\+/_/g' ; }
+
+[ -z "$EXPORT_LIB" ] && cat << EOF
+# THIS FILE IS AUTO-GENERATED AND SHOULD NOT BE SAVED TO DISK!!! Use with
+# vdirsyncer by piping the output of this script to a named pipe.
+
+[general]
+status_path = "$VDIRSYNCER_STATUS_PATH"
+
+EOF
+
+[ -n "$EXPORT_LIB" ] && _cfg_dav() { true ; }
+[ -z "$EXPORT_LIB" ] && _cfg_dav() {
+ cat << EOF
+[pair $ID]
+a = "${ID}_local"
+b = "${ID}_remote"
+collections = ["from a", "from b"]
+metadata = ["displayname", "color"]
+
+[storage ${ID}_local]
+type = "filesystem"
+path = "$VDIRSYNCER_PREFIX/$ID/"
+fileext = "$FILEEXT"
+
+[storage ${ID}_remote]
+type = "$DAV_TYPE"
+url = "$BASE_URL"
+EOF
+ [ -n "$USERNAME" ] && echo "username = \"$USERNAME\""
+ [ -n "$PASSWORD" ] && echo "password = \"$PASSWORD\""
+
+ echo # trailing blank line
+}
+
+[ -n "$EXPORT_LIB" ] && _cfg_ical() { true ; }
+[ -z "$EXPORT_LIB" ] && _cfg_ical() {
+ cat << EOF
+[pair $ID]
+a = "${ID}_remote"
+b = "${ID}_local"
+collections = null
+
+[storage ${ID}_local]
+type = "filesystem"
+path = "$VDIRSYNCER_PREFIX/$ID/"
+fileext = ".ics"
+
+[storage ${ID}_remote]
+type = "http"
+url = "${URL}"
+EOF
+
+ [ -n "$USERNAME" ] && echo "username = \"$USERNAME\""
+ [ -n "$PASSWORD" ] && echo "password = \"$PASSWORD\""
+
+ echo # trailing blank line
+}
+
+ical() {
+ URL="$1"
+ USERNAME="$2" # optional
+ PASSWORD="$3" # optional
+
+ NAME="${NAME-"$(basename "$URL")"}"
+ ID="$(safeify "$NAME")"
+
+ _cfg_ical
+}
+
+caldav() { DAV_TYPE="caldav" dav "$@" ; }
+carddav() { DAV_TYPE="carddav" dav "$@" ; }
+dav() {
+ BASE_URL="$1"
+ USERNAME="$2" # optional
+ PASSWORD="$3" # optional
+
+ ID="$(safeify "$(echo "$BASE_URL$DAV_TYPE" | sed -e 's#^https\?://##' -e 's#/.*##')")"
+
+ [ "$DAV_TYPE" = "caldav" ] && FILEEXT=".ics"
+ [ "$DAV_TYPE" = "carddav" ] && FILEEXT=".vcf"
+
+ # only generate specific DAV config if explicitly defined
+ if [ -n "$DAV_TYPE" ] ; then
+ _cfg_dav
+ return
+ fi
+
+ # else generate both
+ caldav "$@"
+ carddav "$@"
+}
+
+# load "actual" config file
+[ -z "$EXPORT_LIB" ] && . "$CONFIG_FILE"
+
+# make inspecting output easier
+[ -z "$EXPORT_LIB" ] && printf '# %s:%s=%s\n' vim ft dosini
+