feat(watcher): add scrollback history logging on window/pane close #2

Merged
rootiest merged 1 commits from feat-scrollback-watcher into main 2026-05-31 03:42:32 +00:00
Owner

Summary

  • Adds watcher.py — a kitty Python watcher that captures terminal scrollback to ~/.terminal_history/ on every window or pane close, regardless of how the terminal is closed (Ctrl+D, keybind, clicking X, full kitty quit)
  • Fixes kitty.conf watcher directive: removes invalid --type=global prefix that caused a FileNotFoundError on every kitty startup, meaning the watcher was never loaded
  • Documents the scrollback feature and its two configurable env vars in README.md

How it works

Two components handle logging:

  1. fish smart_exit (existing) — intercepts graceful exit calls, logs scrollback via kitty @, and sets logged_by_shell=true on the window to signal the Python watcher to skip it
  2. watcher.py (new) — registers on_close (fires per window on destruction) and on_quit (fires when kitty quits, iterates all windows) hooks; skips windows already logged by the shell or already logged in this session

Manual Verification

  • Restart kitty fully and confirm no watcher errors in journalctl --user _COMM=kitty
  • Open a pane, run some commands, close it with Ctrl+D — verify a new scrollback_*.log appears in ~/.terminal_history/
  • Close a pane via kitty keybind (not shell exit) — verify a log is created
  • Close a full kitty window (multiple panes) — verify one log per pane appears
  • Run exit in a fish shell — verify only one log is created (not duplicated by both fish and watcher)
## Summary - Adds `watcher.py` — a kitty Python watcher that captures terminal scrollback to `~/.terminal_history/` on every window or pane close, regardless of how the terminal is closed (Ctrl+D, keybind, clicking X, full kitty quit) - Fixes `kitty.conf` watcher directive: removes invalid `--type=global` prefix that caused a `FileNotFoundError` on every kitty startup, meaning the watcher was never loaded - Documents the scrollback feature and its two configurable env vars in `README.md` ## How it works Two components handle logging: 1. **fish `smart_exit`** (existing) — intercepts graceful `exit` calls, logs scrollback via `kitty @`, and sets `logged_by_shell=true` on the window to signal the Python watcher to skip it 2. **`watcher.py`** (new) — registers `on_close` (fires per window on destruction) and `on_quit` (fires when kitty quits, iterates all windows) hooks; skips windows already logged by the shell or already logged in this session ## Manual Verification - [x] Restart kitty fully and confirm no watcher errors in `journalctl --user _COMM=kitty` - [x] Open a pane, run some commands, close it with `Ctrl+D` — verify a new `scrollback_*.log` appears in `~/.terminal_history/` - [x] Close a pane via kitty keybind (not shell exit) — verify a log is created - [x] Close a full kitty window (multiple panes) — verify one log per pane appears - [x] Run `exit` in a fish shell — verify only one log is created (not duplicated by both fish and watcher)
rootiest added 1 commit 2026-05-31 03:41:27 +00:00
Introduces watcher.py — a kitty Python watcher that captures terminal
scrollback to ~/.terminal_history/ whenever any window or pane is closed
via Ctrl+D, keybind, or full kitty quit. Works alongside the fish
smart_exit function, which handles graceful shell exits and sets a
user var flag to prevent duplicate logs.

Fixes the kitty.conf watcher directive (removed invalid --type=global
prefix that caused a FileNotFoundError on every kitty startup).
rootiest merged commit 9228f55709 into main 2026-05-31 03:42:32 +00:00
rootiest deleted branch feat-scrollback-watcher 2026-05-31 03:42:32 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: rootiest/kitty-config#2