微算力 · API 导航与自营网关
API 接入 EN
未登录登录
📅

终端日历同步与高效管理

Caldav Calendar 1.0.1 · v1.0.0
效率 安全 A 级 作者 bigdonuts0 公开目录收录
下载 2.1k 安装 1 收藏 8.4k 浏览 13
原始页面

简介

通过 vdirsyncer 将 CalDAV 日历同步至本地,使用 khal 在终端高效查询、搜索与编辑日程事件,支持 iCloud/Google/Fastmail/Nextcloud 等主流服务。

原始描述

Sync and query CalDAV calendars (iCloud, Google, Fastmail, Nextcloud, etc.) using vdirsyncer + khal. Works on Linux.

中文使用说明 来自收录源

核心用法

本技能基于 vdirsyncer + khal 组合,为 Linux 用户提供完整的终端日历管理方案。工作流程遵循「同步 → 操作 → 再同步」的三步模式:

  1. 同步机制:vdirsyncer sync 将远程 CalDAV 日历(iCloud、Google、Fastmail、Nextcloud 等)双向同步至本地 .ics 文件,支持离线查阅与冲突解决策略(如 a wins)。
  2. 查询与搜索:khal list 支持多维度视图——当日、明日、未来 N 天、指定日期范围,并可按日历过滤(-a Work)。khal search 提供全文检索,配合 --format 自定义输出模板,便于脚本集成。
  3. 事件管理:khal new 创建标准/全天/跨日历事件,支持内嵌描述(:: 分隔符);khal edit 以交互式菜单编辑摘要、时间、地点等字段,内置删除功能(D 键)。
  4. 配置架构:vdirsyncer 负责协议层(CalDAV/文件系统),khal 负责展示层,两者通过统一的本地 .ics 目录解耦,配置分别位于 ~/.config/vdirsyncer/config 与 ~/.config/khal/config。

显著优点

  • 开放生态:支持主流 CalDAV 服务商,非锁定于单一平台。
  • 离线优先:本地 .ics 副本确保无网络时仍可查阅完整日程。
  • 终端原生:轻量化、低资源占用,适合 SSH 远程服务器或 tmux 工作流。
  • 脚本友好:丰富的格式化占位符({uid}, {start-time}, {calendar} 等)支持自动化处理。
  • 双向同步:修改本地后推回云端,保持多端一致。

潜在局限

  • 配置门槛:INI 格式双配置(vdirsyncer + khal)对新手不够直观,需手动处理 URL、认证、目录映射。
  • 无图形界面:纯 TUI 交互,复杂日程可视化(月视图重叠事件)体验弱于 GUI 应用。
  • 同步延迟:依赖手动执行 vdirsyncer sync,无后台守护进程(需配合 cron/systemd 定时任务)。
  • 编辑依赖 TTY:khal edit 需交互式终端,自动化场景下难以直接调用。

适合人群

  • 偏好键盘驱动工作流的开发者与运维人员
  • 需要在无 GUI 环境(服务器、WSL)管理日历的技术用户
  • 追求数据本地化的隐私敏感型用户
  • 需将日程数据与 shell 脚本/CI 流程集成的自动化场景

常规风险

  • 凭证安全:vdirsyncer 配置需明文存储或命令获取密码,建议使用权限受限的文件(600)或密钥管理工具。
  • 数据冲突:双向同步可能产生冲突,需预设 conflict_resolution 策略并定期检查状态目录。
  • 缓存失效:khal 的 SQLite 缓存(~/.local/share/khal/khal.db)可能滞后,需手动清理或重启。
  • 误删恢复:khal edit 的删除操作不可逆,且直接修改 .ics 文件可能导致格式损坏,建议定期备份 ~/.local/share/vdirsyncer/ 目录。

技能正文


name: caldav-calendar description: Sync and query CalDAV calendars (iCloud, Google, Fastmail, Nextcloud, etc.) using vdirsyncer + khal. Works on Linux. metadata: {"clawdbot":{"emoji":"📅","os":["linux"],"requires":{"bins":["vdirsyncer","khal"]},"install":[{"id":"apt","kind":"apt","packages":["vdirsyncer","khal"],"bins":["vdirsyncer","khal"],"label":"Install vdirsyncer + khal via apt"}]}}

CalDAV Calendar (vdirsyncer + khal)

vdirsyncer syncs CalDAV calendars to local .ics files. khal reads and writes them.

Sync First

Always sync before querying or after making changes:

vdirsyncer sync

View Events

khal list                        # Today
khal list today 7d               # Next 7 days
khal list tomorrow               # Tomorrow
khal list 2026-01-15 2026-01-20  # Date range
khal list -a Work today          # Specific calendar

Search

khal search "meeting"
khal search "dentist" --format "{start-date} {title}"

Create Events

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

After creating, sync to push changes:

vdirsyncer sync

Edit Events (interactive)

khal edit is interactive — requires a TTY. Use tmux if automating:

khal edit "search term"
khal edit -a CalendarName "search term"
khal edit --show-past "old event"

Menu options:

  • s → edit summary
  • d → edit description
  • t → edit datetime range
  • l → edit location
  • D → delete event
  • n → skip (save changes, next match)
  • q → quit

After editing, sync:

vdirsyncer sync

Delete Events

Use khal edit, then press D to delete.

Output Formats

For scripting:

khal list --format "{start-date} {start-time}-{end-time} {title}" today 7d
khal list --format "{uid} | {title} | {calendar}" today

Placeholders: {title}, {description}, {start}, {end}, {start-date}, {start-time}, {end-date}, {end-time}, {location}, {calendar}, {uid}

Caching

khal caches events in ~/.local/share/khal/khal.db. If data looks stale after syncing:

rm ~/.local/share/khal/khal.db

Initial Setup

1. Configure vdirsyncer (~/.config/vdirsyncer/config)

Example for iCloud:

[general]
status_path = "~/.local/share/vdirsyncer/status/"

[pair icloud_calendar]
a = "icloud_remote"
b = "icloud_local"
collections = ["from a", "from b"]
conflict_resolution = "a wins"

[storage icloud_remote]
type = "caldav"
url = "https://caldav.icloud.com/"
username = "your@icloud.com"
password.fetch = ["command", "cat", "~/.config/vdirsyncer/icloud_password"]

[storage icloud_local]
type = "filesystem"
path = "~/.local/share/vdirsyncer/calendars/"
fileext = ".ics"

Provider URLs:

  • iCloud: https://caldav.icloud.com/
  • Google: Use google_calendar storage type
  • Fastmail: https://caldav.fastmail.com/dav/calendars/user/EMAIL/
  • Nextcloud: https://YOUR.CLOUD/remote.php/dav/calendars/USERNAME/

2. Configure khal (~/.config/khal/config)

[calendars]
[[my_calendars]]
path = ~/.local/share/vdirsyncer/calendars/*
type = discover

[default]
default_calendar = Home
highlight_event_days = True

[locale]
timeformat = %H:%M
dateformat = %Y-%m-%d

3. Discover and sync

vdirsyncer discover   # First time only
vdirsyncer sync

正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。

标签

calendarcaldavsyncterminalclilinuxproductivityvdirsyncerkhalicloudgoogle-calendarnextcloudautomation

同类 Skill