CalDAV Calendar(vdirsyncer + khal)是一个在 Linux 上同步与查询 CalDAV 日历的命令行技能。其基本分工是:vdirsyncer 将远端 CalDAV 日历同步到本地的 .ics 文件,khal 负责读取和写入这些文件。
【用途】 通过命令行访问、检索和维护 CalDAV 日历,适配 iCloud、Google、Fastmail、Nextcloud 等支持 CalDAV 的服务。适用于希望在终端内查看日程、搜索事件、创建或修改事件的场景。
【主要能力】
- 查看事件:khal list 查看今天,khal list today 7d 查看未来 7 天,khal list tomorrow 查看明天,khal list 2026-01-15 2026-01-20 按日期范围查看,khal list -a Work today 指定日历。
- 搜索:khal search "meeting",或使用 --format "{start-date} {title}" 自定义输出。
- 创建事件:khal new 2026-01-15 10:00 11:00 "Meeting title" 创建带时间段事件,khal new 2026-01-15 "All day event" 创建全天事件,khal new tomorrow 14:00 15:30 "Call" -a Work 指定日历,使用 :: 附加描述,例如 khal new 2026-01-15 10:00 11:00 "With notes" :: Description goes here。
- 编辑事件:khal edit 为交互式操作,需要 TTY,自动化时可使用 tmux;支持 khal edit "search term"、khal edit -a CalendarName "search term"、khal edit --show-past "old event"。交互菜单中 s 编辑摘要、d 编辑描述、t 编辑时间范围、l 编辑地点、D 删除事件、n 跳过并保存继续匹配下一项、q 退出。
- 删除事件:通过 khal edit 后按 D 完成删除。
- 输出格式:提供 {title}、{description}、{start}、{end}、{start-date}、{start-time}、{end-date}、{end-time}、{location}、{calendar}、{uid} 等占位符,便于脚本处理。
【使用方式】 使用流程强调先同步:查询前执行 vdirsyncer sync 获取最新数据;创建或编辑后再执行一次 vdirsyncer sync 将变更推送到远端。
初始配置分三步:
- 配置 vdirsyncer(~/.config/vdirsyncer/config)。示例(iCloud)包含 [general] 的 status_path、[pair icloud_calendar] 的 a/b/collections/conflict_resolution、[storage icloud_remote] 的 type/url/username/password.fetch,以及 [storage icloud_local] 的 type/path/fileext。各服务 CalDAV 地址:iCloud 为 https://caldav.icloud.com/;Google 使用 google_calendar 存储类型;Fastmail 为 https://caldav.fastmail.com/dav/calendars/user/EMAIL/;Nextcloud 为 https://YOUR.CLOUD/remote.php/dav/calendars/USERNAME/。
- 配置 khal(~/.config/khal/config),示例包含 [calendars]、[[my_calendars]] 的 path 与 type = discover、[default] 的 default_calendar 与 highlight_event_days、[locale] 的 timeformat 与 dateformat。
- 首次发现并同步:vdirsyncer discover(仅首次),然后 vdirsyncer sync。
【缓存】 khal 将事件缓存在 ~/.local/share/khal/khal.db。如果同步后数据看起来仍是旧的,可删除该文件:rm ~/.local/share/khal/khal.db。
【限制】 该技能在 Linux 上运行;khal edit 为交互式操作、需要 TTY,自动化场景需借助 tmux。其他限制(如具体版本要求、权限细节)资料暂未提供。