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
|
||||
|
||||
# ── khal (CLI calendar companion) ────────────────────────────────────────────
|
||||
log "Writing ~/.config/khal/config..."
|
||||
log "Writing ~/.config/khal/config (per-calendar entries)..."
|
||||
mkdir -p ~/.config/khal
|
||||
cat > ~/.config/khal/config << EOF
|
||||
[calendars]
|
||||
[[personal]]
|
||||
path = $CALDAV_DIR/*
|
||||
color = light blue
|
||||
python3 - "$CALDAV_DIR" << 'PYEOF'
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
[sqlite]
|
||||
path = ~/.local/share/khal/khal.db
|
||||
cal_root = Path(sys.argv[1])
|
||||
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]
|
||||
timeformat = %H:%M
|
||||
dateformat = %Y-%m-%d
|
||||
datetimeformat = %Y-%m-%d %H:%M
|
||||
EOF
|
||||
lines = ["[calendars]"]
|
||||
for i, d in enumerate(dirs):
|
||||
lines += [f" [[{d.name}]]", f" path = {d}", f" color = {colors[i % len(colors)]}"]
|
||||
|
||||
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 ───────────────────────────────────────
|
||||
log "Installing ics-to-calendarim converter..."
|
||||
|
|
@ -87,8 +93,10 @@ except ImportError:
|
|||
|
||||
CALDAV_DIR = Path.home() / ".local/share/calendars"
|
||||
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):
|
||||
if isinstance(dt, datetime):
|
||||
|
|
@ -145,6 +153,18 @@ def main():
|
|||
(out / "0").write_text(json.dumps({"items": events}))
|
||||
|
||||
(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).")
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
Loading…
Reference in New Issue