Compare commits

...

7 Commits

Author SHA1 Message Date
Amir Alexander Abdelbaki 325c6def66 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>
2026-05-26 14:40:37 +02:00
Amir Alexander Abdelbaki f25b761f3d fix(nvim): replace calendar.vim with khal interactive for event display
calendar.vim hangs on Google token errors; khal interactive reads the
same vdirsyncer ICS files directly and provides a working calendar+event TUI.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-26 14:26:17 +02:00
Amir Alexander Abdelbaki dc11cc007d feat(nvim): enable calendar.vim event loading from local ICS cache
Sets g:calendar_google_calendar so calendar.vim attempts to load events,
falling back to the cache populated by ics-to-calendarim.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-26 14:23:32 +02:00
Amir Alexander Abdelbaki 5948629c28 feat(nvim): sync CalDAV on startup via background jobstart
Runs vdirsyncer sync + ics-to-calendarim in a detached background job
on VimEnter so the calendar.vim cache stays fresh without blocking startup.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-26 14:12:24 +02:00
Amir Alexander Abdelbaki e454482970 feat(caldav): add CalDAV sync script with calendar.vim cache converter
Installs vdirsyncer + khal, writes vdirsyncer/khal configs, creates
ics-to-calendarim converter to populate calendar.vim local JSON cache,
and sets up a systemd user timer for 15-minute periodic sync.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-26 14:11:06 +02:00
Amir Alexander Abdelbaki 211763d2c8 fix(nvim): guarantee abook pane is at least 20 lines tall
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-26 13:40:45 +02:00
Amir Alexander Abdelbaki c2514b6fb5 fix(nvim): guarantee abook/calendar column is at least 80 cols wide
Right column was derived as W - left_w, making it too narrow on smaller
terminals. Now right_w = max(80, 45% of W) and left_w takes the rest.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-26 13:39:04 +02:00
2 changed files with 231 additions and 7 deletions

View File

@ -64,6 +64,7 @@ vim.g.airline_section_x = "IP:" .. ipaddr .. " DNS:" .. hostname
vim.g.loaded_ruby_provider = 0
vim.g.loaded_perl_provider = 0
-- ── Editor options ────────────────────────────────────────────────────────────
vim.cmd("filetype plugin indent on")
vim.cmd("syntax enable")
@ -231,7 +232,7 @@ local function toggle_solo(key, cmd, label)
end
vim.keymap.set("n", "n", function() toggle_solo("n", "terminal alot", "alot") end, { silent = true })
vim.keymap.set("n", "g", function() toggle_solo("g", "Calendar -position=here", "calendar.vim") end, { silent = true })
vim.keymap.set("n", "g", function() toggle_solo("g", "terminal khal interactive", "khal") end, { silent = true })
vim.keymap.set("n", "f", function() toggle_solo("f", "terminal abook", "abook") end, { silent = true })
-- r: sideward-T overlay — left column (bar of the T) with three stacked panes,
@ -248,10 +249,10 @@ local function toggle_pim()
-- full-screen: alot left, abook top-right, calendar bottom-right
local H = vim.o.lines - 2
local W = vim.o.columns
local left_w = math.max(1, math.floor(W * 0.55))
local right_w = math.max(1, W - left_w)
local top_h = math.max(1, math.floor(H / 2))
local bot_h = math.max(1, H - top_h)
local right_w = math.max(80, math.floor(W * 0.45))
local left_w = math.max(1, W - right_w)
local top_h = math.max(20, math.floor(H / 2))
local bot_h = math.max(1, H - top_h)
local w1 = _pim_float(0, 0, H, left_w)
local ok, err = pcall(vim.cmd, "terminal alot")
@ -262,11 +263,22 @@ local function toggle_pim()
if not ok then _pim_scratch("abook", err) end
local w3 = _pim_float(top_h, left_w, bot_h, right_w)
ok, err = pcall(vim.cmd, "Calendar -position=here")
if not ok then _pim_scratch("calendar.vim", err) end
ok, err = pcall(vim.cmd, "terminal khal interactive")
if not ok then _pim_scratch("khal", err) end
_pim_wins = { w1, w2, w3 }
vim.api.nvim_set_current_win(w1)
end
vim.keymap.set("n", "x", toggle_pim, { silent = true })
-- ── CalDAV background sync on startup ────────────────────────────────────────
vim.api.nvim_create_autocmd("VimEnter", {
once = true,
callback = function()
vim.fn.jobstart(
{ "sh", "-c", "vdirsyncer sync && ics-to-calendarim" },
{ detach = true }
)
end,
})

View File

@ -0,0 +1,212 @@
#!/bin/bash
set -euo pipefail
source "$(dirname "${BASH_SOURCE[0]}")/../../lib/logging.sh"
log "Installing CalDAV sync stack..."
sudo pacman -S --noconfirm --needed vdirsyncer khal python-icalendar
# ── Credentials ───────────────────────────────────────────────────────────────
read -rp "CalDAV server URL (e.g. https://dav.example.com/cal/): " CALDAV_URL
read -rp "Username : " CALDAV_USER
read -rsp "Password : " CALDAV_PASS; echo
read -rp "Calendar display name [Personal] : " CAL_NAME
CAL_NAME="${CAL_NAME:-Personal}"
CALDAV_DIR="$HOME/.local/share/calendars"
mkdir -p "$CALDAV_DIR"
# ── vdirsyncer ────────────────────────────────────────────────────────────────
log "Writing ~/.config/vdirsyncer/config..."
mkdir -p ~/.config/vdirsyncer ~/.local/share/vdirsyncer/status
cat > ~/.config/vdirsyncer/config << EOF
[general]
status_path = "$HOME/.local/share/vdirsyncer/status/"
[pair calendars]
a = "local_cals"
b = "remote_cals"
collections = ["from b"]
metadata = ["color", "displayname"]
[storage local_cals]
type = "filesystem"
path = "$CALDAV_DIR"
fileext = ".ics"
[storage remote_cals]
type = "caldav"
url = "$CALDAV_URL"
username = "$CALDAV_USER"
password = "$CALDAV_PASS"
EOF
chmod 600 ~/.config/vdirsyncer/config
log "Discovering CalDAV collections (confirm any prompts with y)..."
yes | vdirsyncer discover calendars || true
log "Running initial sync..."
vdirsyncer sync
# ── khal (CLI calendar companion) ────────────────────────────────────────────
log "Writing ~/.config/khal/config (per-calendar entries)..."
mkdir -p ~/.config/khal
python3 - "$CALDAV_DIR" << 'PYEOF'
import sys
from pathlib import Path
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())
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..."
mkdir -p ~/.local/bin
cat > ~/.local/bin/ics-to-calendarim << 'PYEOF'
#!/usr/bin/env python3
"""
Convert vdirsyncer ICS files to calendar.vim local event cache.
Cache lives at ~/.cache/calendar.vim/local/ in the format:
calendarList list of calendars (JSON)
<id>/<YYYY>/<MM>/0 events per month (JSON)
"""
import json, sys
from pathlib import Path
from datetime import datetime, date, timezone
try:
from icalendar import Calendar as iCal
except ImportError:
sys.exit("python-icalendar is required: sudo pacman -S python-icalendar")
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"]
KHAL_COLORS = ["light blue", "light green", "light red", "light magenta", "light cyan"]
def to_naive(dt):
if isinstance(dt, datetime):
if dt.tzinfo is not None:
dt = dt.astimezone(timezone.utc).replace(tzinfo=None)
return dt.strftime("%Y-%m-%dT%H:%M:%S"), True, dt.year, dt.month
if isinstance(dt, date):
return dt.strftime("%Y-%m-%d"), False, dt.year, dt.month
return None, False, None, None
def main():
CACHE_DIR.mkdir(parents=True, exist_ok=True)
cal_items = []
for idx, cal_dir in enumerate(sorted(d for d in CALDAV_DIR.iterdir() if d.is_dir())):
cal_id = cal_dir.name
cal_summary = cal_dir.name.replace("_", " ").title()
cal_items.append({
"id": cal_id,
"summary": cal_summary,
"backgroundColor": COLORS[idx % len(COLORS)],
"foregroundColor": "#ffffff",
})
by_month: dict = {}
for ics in cal_dir.glob("*.ics"):
try:
cal = iCal.from_ical(ics.read_bytes())
except Exception as e:
print(f"warning: skipping {ics.name}: {e}", file=sys.stderr)
continue
for comp in cal.walk("VEVENT"):
dtstart = comp.get("DTSTART")
dtend = comp.get("DTEND") or comp.get("DTSTART")
if not dtstart:
continue
s_str, is_timed, yr, mo = to_naive(dtstart.dt)
e_str, _, _, _ = to_naive(dtend.dt)
if not s_str:
continue
uid = str(comp.get("UID", ics.stem))
summary = str(comp.get("SUMMARY", ""))
key = (yr, mo)
by_month.setdefault(key, []).append({
"id": uid,
"summary": summary,
"start": {"dateTime": s_str} if is_timed else {"date": s_str},
"end": {"dateTime": e_str} if is_timed else {"date": e_str},
})
for (yr, mo), events in by_month.items():
out = CACHE_DIR / cal_id / f"{yr:04d}" / f"{mo:02d}"
out.mkdir(parents=True, exist_ok=True)
(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__":
main()
PYEOF
chmod +x ~/.local/bin/ics-to-calendarim
log "Running initial calendar.vim cache build..."
~/.local/bin/ics-to-calendarim
# ── systemd user timer ────────────────────────────────────────────────────────
log "Installing vdirsyncer systemd user timer (every 15 min)..."
mkdir -p ~/.config/systemd/user
cat > ~/.config/systemd/user/vdirsyncer.service << EOF
[Unit]
Description=Sync CalDAV and rebuild calendar.vim cache
After=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/bin/vdirsyncer sync
ExecStartPost=$HOME/.local/bin/ics-to-calendarim
EOF
cat > ~/.config/systemd/user/vdirsyncer.timer << EOF
[Unit]
Description=Run vdirsyncer every 15 minutes
[Timer]
OnBootSec=2min
OnUnitActiveSec=15min
Unit=vdirsyncer.service
[Install]
WantedBy=timers.target
EOF
systemctl --user daemon-reload
systemctl --user enable --now vdirsyncer.timer
log "CalDAV sync configured. Events will appear in calendar.vim automatically."
log "Manual sync: vdirsyncer sync && ics-to-calendarim"
log "CLI calendar: khal list / khal interactive"
log "Timer status: systemctl --user status vdirsyncer.timer"