fix(caldav): write per-calendar khal config instead of broken glob
The glob path = .../calendars/* was not expanded by khal, so no events were visible. Now caldav-sync.sh and ics-to-calendarim both generate explicit [[name]]/path entries per calendar and regenerate the config on every sync so newly discovered calendars are picked up automatically. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>main
parent
f25b761f3d
commit
325c6def66
|
|
@ -48,22 +48,28 @@ log "Running initial sync..."
|
||||||
vdirsyncer sync
|
vdirsyncer sync
|
||||||
|
|
||||||
# ── khal (CLI calendar companion) ────────────────────────────────────────────
|
# ── khal (CLI calendar companion) ────────────────────────────────────────────
|
||||||
log "Writing ~/.config/khal/config..."
|
log "Writing ~/.config/khal/config (per-calendar entries)..."
|
||||||
mkdir -p ~/.config/khal
|
mkdir -p ~/.config/khal
|
||||||
cat > ~/.config/khal/config << EOF
|
python3 - "$CALDAV_DIR" << 'PYEOF'
|
||||||
[calendars]
|
import sys
|
||||||
[[personal]]
|
from pathlib import Path
|
||||||
path = $CALDAV_DIR/*
|
|
||||||
color = light blue
|
|
||||||
|
|
||||||
[sqlite]
|
cal_root = Path(sys.argv[1])
|
||||||
path = ~/.local/share/khal/khal.db
|
colors = ["light blue", "light green", "light red", "light magenta", "light cyan"]
|
||||||
|
dirs = sorted(d for d in cal_root.iterdir() if d.is_dir())
|
||||||
|
|
||||||
[locale]
|
lines = ["[calendars]"]
|
||||||
timeformat = %H:%M
|
for i, d in enumerate(dirs):
|
||||||
dateformat = %Y-%m-%d
|
lines += [f" [[{d.name}]]", f" path = {d}", f" color = {colors[i % len(colors)]}"]
|
||||||
datetimeformat = %Y-%m-%d %H:%M
|
|
||||||
EOF
|
lines += [
|
||||||
|
"", "[sqlite]", "path = ~/.local/share/khal/khal.db",
|
||||||
|
"", "[locale]", "timeformat = %H:%M", "dateformat = %Y-%m-%d",
|
||||||
|
"datetimeformat = %Y-%m-%d %H:%M",
|
||||||
|
]
|
||||||
|
|
||||||
|
(Path.home() / ".config/khal/config").write_text("\n".join(lines) + "\n")
|
||||||
|
PYEOF
|
||||||
|
|
||||||
# ── ICS → calendar.vim cache converter ───────────────────────────────────────
|
# ── ICS → calendar.vim cache converter ───────────────────────────────────────
|
||||||
log "Installing ics-to-calendarim converter..."
|
log "Installing ics-to-calendarim converter..."
|
||||||
|
|
@ -87,8 +93,10 @@ except ImportError:
|
||||||
|
|
||||||
CALDAV_DIR = Path.home() / ".local/share/calendars"
|
CALDAV_DIR = Path.home() / ".local/share/calendars"
|
||||||
CACHE_DIR = Path.home() / ".cache/calendar.vim/local"
|
CACHE_DIR = Path.home() / ".cache/calendar.vim/local"
|
||||||
|
KHAL_CFG = Path.home() / ".config/khal/config"
|
||||||
|
|
||||||
COLORS = ["#4CAF50", "#2196F3", "#FF5722", "#9C27B0", "#FF9800"]
|
COLORS = ["#4CAF50", "#2196F3", "#FF5722", "#9C27B0", "#FF9800"]
|
||||||
|
KHAL_COLORS = ["light blue", "light green", "light red", "light magenta", "light cyan"]
|
||||||
|
|
||||||
def to_naive(dt):
|
def to_naive(dt):
|
||||||
if isinstance(dt, datetime):
|
if isinstance(dt, datetime):
|
||||||
|
|
@ -145,6 +153,18 @@ def main():
|
||||||
(out / "0").write_text(json.dumps({"items": events}))
|
(out / "0").write_text(json.dumps({"items": events}))
|
||||||
|
|
||||||
(CACHE_DIR / "calendarList").write_text(json.dumps({"items": cal_items}))
|
(CACHE_DIR / "calendarList").write_text(json.dumps({"items": cal_items}))
|
||||||
|
|
||||||
|
# regenerate khal config so new calendars are picked up automatically
|
||||||
|
cal_dirs = sorted(d for d in CALDAV_DIR.iterdir() if d.is_dir())
|
||||||
|
khal_lines = ["[calendars]"]
|
||||||
|
for i, d in enumerate(cal_dirs):
|
||||||
|
khal_lines += [f" [[{d.name}]]", f" path = {d}",
|
||||||
|
f" color = {KHAL_COLORS[i % len(KHAL_COLORS)]}"]
|
||||||
|
khal_lines += ["", "[sqlite]", "path = ~/.local/share/khal/khal.db",
|
||||||
|
"", "[locale]", "timeformat = %H:%M", "dateformat = %Y-%m-%d",
|
||||||
|
"datetimeformat = %Y-%m-%d %H:%M"]
|
||||||
|
KHAL_CFG.write_text("\n".join(khal_lines) + "\n")
|
||||||
|
|
||||||
print(f"calendar.vim cache updated: {len(cal_items)} calendar(s).")
|
print(f"calendar.vim cache updated: {len(cal_items)} calendar(s).")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue