aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-11-14 11:27:41 +0100
committerDanilo M. <danix@danix.xyz>2026-11-14 11:27:41 +0100
commitc39361726fa9cf1623d49ea1b9b2dd7e43f67622 (patch)
treef48bdef65dc66546e9b486a6379d2cd6515d1af4 /bin
parent7ade0f07325d5fb92e530b6ec1bb8d4f9896be73 (diff)
downloadconky-theme-udt-c39361726fa9cf1623d49ea1b9b2dd7e43f67622.tar.gz
conky-theme-udt-c39361726fa9cf1623d49ea1b9b2dd7e43f67622.zip
feat(calendar): list due tasks from a task vdir beside the events
The sampler reads open VTODOs with a due date from ~/.local/share/tasks/<list>/*.ics (a vdirsyncer filesystem storage, override with UDT_TASKS_DIR) and writes them to the cache as ISO 'task' lines. The card merges them into the week's rows by date, with a checkbox before the title and an urgency colour: overdue critical, due today warning, later label. Overdue tasks stay until done, so they lead the table. Tasks never mark the month grid. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'bin')
-rwxr-xr-xbin/calendar-sample.sh49
1 files changed, 49 insertions, 0 deletions
diff --git a/bin/calendar-sample.sh b/bin/calendar-sample.sh
index a0fb87e..c24e756 100755
--- a/bin/calendar-sample.sh
+++ b/bin/calendar-sample.sh
@@ -57,6 +57,12 @@ EVENTS=$(khal list --day-format '' \
--format '{start-date-long}|{start-time}|{end-time}|{calendar}|{title}' \
--notstarted today "${DAYS}d" 2>/dev/null)
+# The task vdir is optional: without it the card shows events only.
+TASKS_DIR="${UDT_TASKS_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/tasks}"
+shopt -s nullglob
+TASK_FILES=("$TASKS_DIR"/*/*.ics)
+shopt -u nullglob
+
# khal's exit status is 0 even with no calendars configured, so emptiness is
# not distinguishable from failure by status alone. The widget treats a missing
# 'generated' key as "the sampler never ran" and an empty event list as "no
@@ -87,6 +93,49 @@ EVENTS=$(khal list --day-format '' \
if [ -n "$EVENTS" ]; then
printf '%s\n' "$EVENTS" | sed 's/^/event /'
fi
+
+ # Open tasks with a due date, from a vdirsyncer task vdir (one VTODO per
+ # .ics, one subdirectory per list). Read directly rather than through a
+ # CLI: the files are plain iCalendar and gawk starts in milliseconds.
+ # Written as 'task YYYY-MM-DD|HH:MM|title', ISO since we control it; the
+ # widget cuts the list to the week, keeping overdue ones.
+ #
+ # Lines are unfolded first (RFC 5545 continuation lines start with a
+ # space). A VALARM inside a VTODO carries its own DESCRIPTION/SUMMARY, so
+ # its properties are skipped. A UTC due time (...Z) is converted to local.
+ # ponytail: a DUE;TZID=... time is taken as local, not converted; fine
+ # while the task server and this desktop share a zone.
+ if [ ${#TASK_FILES[@]} -gt 0 ]; then
+ gawk '
+ function prop(line, name, val, p, d) {
+ p = index(line, ":"); if (!p) return
+ name = substr(line, 1, p - 1); val = substr(line, p + 1)
+ if (line == "BEGIN:VTODO") { todo = 1; alarm = 0; due = summary = status = ""; return }
+ if (line == "BEGIN:VALARM") { alarm = 1; return }
+ if (line == "END:VALARM") { alarm = 0; return }
+ if (line == "END:VTODO") {
+ if (todo && due != "" && status != "COMPLETED" && status != "CANCELLED")
+ print "task " due "|" summary
+ todo = 0; return
+ }
+ if (!todo || alarm) return
+ sub(/;.*/, "", name)
+ if (name == "STATUS") status = val
+ else if (name == "SUMMARY") {
+ gsub(/\\[nN]/, " ", val)
+ summary = gensub(/\\([,;\\])/, "\\1", "g", val)
+ } else if (name == "DUE" && match(val, /^([0-9]{4})([0-9]{2})([0-9]{2})(T([0-9]{2})([0-9]{2})([0-9]{2})(Z?))?/, d)) {
+ if (d[4] == "") due = d[1] "-" d[2] "-" d[3] "|"
+ else due = strftime("%Y-%m-%d|%H:%M",
+ mktime(d[1] " " d[2] " " d[3] " " d[5] " " d[6] " " d[7], d[8] == "Z"))
+ }
+ }
+ { sub(/\r$/, "") }
+ /^[ \t]/ { cur = cur substr($0, 2); next }
+ { prop(cur); cur = $0 }
+ ENDFILE { prop(cur); cur = "" }
+ ' "${TASK_FILES[@]}" 2>/dev/null
+ fi
} > "$TMP"
mv -f "$TMP" "$CACHE"