aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.config/khal/base14
l---------.config/khal/config.sh1
-rwxr-xr-x.config/khal/config_gen56
-rw-r--r--.config/vdirsyncer/config.sh.example29
-rwxr-xr-x.config/vdirsyncer/config_gen99
-rwxr-xr-x.local/share/bin/khal14
-rwxr-xr-x.local/share/bin/vdirsyncer6
7 files changed, 219 insertions, 0 deletions
diff --git a/.config/khal/base b/.config/khal/base
new file mode 100644
index 0000000..2a8238d
--- /dev/null
+++ b/.config/khal/base
@@ -0,0 +1,14 @@
+# vim:ft=dosini
+
+[locale]
+timeformat = %H:%M
+dateformat = %m月%d日 (%a)
+longdateformat = %A %Y年%m月%d日
+datetimeformat = %c
+longdatetimeformat = %c
+
+[view]
+agenda_day_format = "{bold}{date-long}{reset}"
+agenda_event_format = " {cancelled}{repeat-symbol}{alarm-symbol}{start-end-time-style} -- {calendar-color}{title}{reset}"
+blank_line_before_day = True
+
diff --git a/.config/khal/config.sh b/.config/khal/config.sh
new file mode 120000
index 0000000..ecf2581
--- /dev/null
+++ b/.config/khal/config.sh
@@ -0,0 +1 @@
+../vdirsyncer/config.sh \ No newline at end of file
diff --git a/.config/khal/config_gen b/.config/khal/config_gen
new file mode 100755
index 0000000..da59fa5
--- /dev/null
+++ b/.config/khal/config_gen
@@ -0,0 +1,56 @@
+#!/bin/sh
+. "$XDG_CONFIG_HOME/vdirsyncer/config_gen" lib
+
+cat << EOF
+[calendars]
+
+EOF
+
+_sync() {
+ yes | vdirsyncer discover 1> /dev/null 2> /dev/null
+ vdirsyncer sync 1> /dev/null 2> /dev/null
+ vdirsyncer metasync 1> /dev/null 2> /dev/null
+}
+
+_color_quantize() {
+ INPUT_HEX="$(echo $1 | grep -o '#[0-9a-fA-F]\{6\}')"
+
+ echo "$INPUT_HEX"
+}
+
+_cfg_caldav() {
+ jq --raw-output '.collections[][0]' "$VDIRSYNCER_STATUS_PATH/$ID.collections" | while read -r collection ; do
+ collection_path="$XDG_DATA_HOME/vdirsyncer/$ID/$collection"
+ color_path="$collection_path/color"
+ displayname_path="$collection_path/displayname"
+ [ ! -d "$collection_path" ] && _sync
+ [ ! -f "$color_path" ] && _sync
+ [ ! -f "$displayname_path" ] && _sync
+ COLOR="$(cat "$color_path")"
+ NAME="$(cat "$displayname_path")"
+ [ -n "$COLOR" ] && [ -n "$QUANTIZE_COLOR" ] && COLOR="$(_color_quantize "$COLOR")"
+ cat << EOF
+[[$NAME]]
+path = "$collection_path"
+EOF
+ [ -n "$COLOR" ] && echo "color = \"$COLOR\""
+ echo
+ done
+}
+
+_cfg_ical() {
+ collection_path="$XDG_DATA_HOME/vdirsyncer/$ID"
+ [ ! -d "$collection_path" ] && _sync
+ cat << EOF
+[[$NAME]]
+path = "$collection_path"
+readonly = True
+EOF
+ [ -n "$COLOR" ] && echo "color = \"$COLOR\""
+
+ echo
+}
+
+. "$CONFIG_FILE"
+
+printf '# %s:%s=%s\n' vim ft dosini
diff --git a/.config/vdirsyncer/config.sh.example b/.config/vdirsyncer/config.sh.example
new file mode 100644
index 0000000..c40bd94
--- /dev/null
+++ b/.config/vdirsyncer/config.sh.example
@@ -0,0 +1,29 @@
+#!/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 (TODO: this is not implemented yet)
+# 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)"
+
+### 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/.config/vdirsyncer/config_gen b/.config/vdirsyncer/config_gen
new file mode 100755
index 0000000..2e536d5
--- /dev/null
+++ b/.config/vdirsyncer/config_gen
@@ -0,0 +1,99 @@
+#!/bin/sh
+CONFIG_FILE="$(dirname "$0")/config.sh"
+[ ! -e "$CONFIG_FILE" ] && {
+ echo "please create $CONFIG_FILE"
+ exit 1
+}
+
+CFG_MODE="$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' ; }
+
+[ "$CFG_MODE" != "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
+
+_cfg_caldav() {
+ 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 = ".ics"
+
+[storage ${ID}_remote]
+type = "caldav"
+url = "${BASE_URL}"
+EOF
+ [ -n "$USERNAME" ] && echo "username = \"$USERNAME\""
+ [ -n "$PASSWORD" ] && echo "password = \"$PASSWORD\""
+
+ echo # trailing blank line
+}
+
+caldav() {
+ BASE_URL="$1"
+ USERNAME="$2" # optional
+ PASSWORD="$3" # optional
+
+ NAME="$(echo "$BASE_URL" | sed -e 's#^https\?://##' -e 's#/.*##')"
+ ID="$(safeify "$NAME")"
+
+ _cfg_caldav
+}
+
+_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
+}
+
+# load "actual" config file
+[ "$CFG_MODE" != "lib" ] && . "$CONFIG_FILE"
+
+# make inspecting output easier
+[ "$CFG_MODE" != "lib" ] && printf '# %s:%s=%s\n' vim ft dosini
+
diff --git a/.local/share/bin/khal b/.local/share/bin/khal
new file mode 100755
index 0000000..23f188a
--- /dev/null
+++ b/.local/share/bin/khal
@@ -0,0 +1,14 @@
+#!/bin/sh
+CFG="$XDG_CONFIG_HOME/khal/config"
+cat - "$XDG_CONFIG_HOME/khal/base" << "EOF" > "$CFG"
+# THIS FILE IS AUTO-GENERATED, EDIT config_gen OR base INSTEAD!!!
+
+EOF
+"$XDG_CONFIG_HOME/khal/config_gen" >> "$CFG"
+
+# aliases
+[ "$1" == "i" ] && { shift ; set -- interactive "$@" ; }
+[ "$1" == "l" ] && { shift ; set -- list "$@" ; }
+
+exec /usr/bin/khal "$@"
+
diff --git a/.local/share/bin/vdirsyncer b/.local/share/bin/vdirsyncer
new file mode 100755
index 0000000..7869f19
--- /dev/null
+++ b/.local/share/bin/vdirsyncer
@@ -0,0 +1,6 @@
+#!/bin/sh
+CFG_TMP="$XDG_CONFIG_HOME/vdirsyncer/config"
+mkfifo --mode 700 "$CFG_TMP"
+"$XDG_CONFIG_HOME/vdirsyncer/config_gen" > "$CFG_TMP" &
+/usr/bin/vdirsyncer --config "$CFG_TMP" "$@"
+rm -f "$CFG_TMP"