feat(shell): add scrollback history capture on shell exit #24

Merged
rootiest merged 1 commits from feat/scrollback-history-on-exit into main 2026-05-30 05:21:48 +00:00
Owner

Summary

  • New smart_exit function — when running inside Kitty, closing an interactive shell with exit automatically saves a timestamped scrollback snapshot to ~/.terminal_history (or SCROLLBACK_HISTORY_DIR). Snapshots are pruned once the count exceeds SCROLLBACK_HISTORY_MAX_FILES (default 100). Pass --no-log / -n to exit without saving.
  • config.fish wiring — exports SCROLLBACK_HISTORY_DIR and SCROLLBACK_HISTORY_MAX_FILES with safe defaults; wraps the exit builtin to route through smart_exit in interactive sessions.
  • cat ANSI passthrough — detects files inside SCROLLBACK_HISTORY_DIR or containing raw ANSI escape sequences and passes them to command cat instead of bat, so color output is preserved when reviewing saved scrollback logs.
  • Cleanup — removes the redundant alias rm="rm -i" from conf.d/tricks.fish; the trash-aware functions/rm.fish wrapper is the authoritative handler and the two conflicted.
  • README sync — new Scrollback History integration section, smart_exit added to the System functions table, cat description updated, stale rm Safety Wrapper entry and its note removed.

Manual Verification

  • Open a Kitty terminal, run a few commands, then type exit — confirm a scrollback_*.log file appears in ~/.terminal_history and contains the session output with ANSI sequences intact.
  • Run exit --no-log — confirm the shell closes without creating a new log file.
  • cat ~/.terminal_history/scrollback_<tab> — confirm the file renders with colors (not garbled by bat syntax highlighting).
  • Run rm somefile in an interactive session — confirm you still get the trash-aware prompt from functions/rm.fish (i.e., the alias removal did not break anything).
  • Check SCROLLBACK_HISTORY_MAX_FILES=3 in local.fish, open and close 4 sessions — confirm only 3 log files remain after the 4th exit.
## Summary - **New `smart_exit` function** — when running inside Kitty, closing an interactive shell with `exit` automatically saves a timestamped scrollback snapshot to `~/.terminal_history` (or `SCROLLBACK_HISTORY_DIR`). Snapshots are pruned once the count exceeds `SCROLLBACK_HISTORY_MAX_FILES` (default 100). Pass `--no-log` / `-n` to exit without saving. - **`config.fish` wiring** — exports `SCROLLBACK_HISTORY_DIR` and `SCROLLBACK_HISTORY_MAX_FILES` with safe defaults; wraps the `exit` builtin to route through `smart_exit` in interactive sessions. - **`cat` ANSI passthrough** — detects files inside `SCROLLBACK_HISTORY_DIR` or containing raw ANSI escape sequences and passes them to `command cat` instead of `bat`, so color output is preserved when reviewing saved scrollback logs. - **Cleanup** — removes the redundant `alias rm="rm -i"` from `conf.d/tricks.fish`; the trash-aware `functions/rm.fish` wrapper is the authoritative handler and the two conflicted. - **README sync** — new _Scrollback History_ integration section, `smart_exit` added to the System functions table, `cat` description updated, stale `rm` Safety Wrapper entry and its note removed. ## Manual Verification - [x] Open a Kitty terminal, run a few commands, then type `exit` — confirm a `scrollback_*.log` file appears in `~/.terminal_history` and contains the session output with ANSI sequences intact. - [x] Run `exit --no-log` — confirm the shell closes without creating a new log file. - [x] `cat ~/.terminal_history/scrollback_<tab>` — confirm the file renders with colors (not garbled by bat syntax highlighting). - [x] Run `rm somefile` in an interactive session — confirm you still get the trash-aware prompt from `functions/rm.fish` (i.e., the alias removal did not break anything). - [x] Check `SCROLLBACK_HISTORY_MAX_FILES=3` in `local.fish`, open and close 4 sessions — confirm only 3 log files remain after the 4th exit.
rootiest added 1 commit 2026-05-30 05:21:20 +00:00
- Add smart_exit function: captures Kitty scrollback to a timestamped
  log file on exit; --no-log/-n skips capture; auto-prunes oldest logs
  once count exceeds SCROLLBACK_HISTORY_MAX_FILES
- Wire exit → smart_exit in config.fish for interactive sessions;
  export SCROLLBACK_HISTORY_DIR and SCROLLBACK_HISTORY_MAX_FILES with
  sane defaults (~/.terminal_history and 100 respectively)
- Update cat to detect files in SCROLLBACK_HISTORY_DIR or containing
  raw ANSI escape sequences and pass them through command cat instead
  of bat, preserving color output
- Remove redundant alias rm="rm -i" from tricks.fish (superseded by
  functions/rm.fish trash-aware wrapper)
- Sync README: new Scrollback History integration section, smart_exit
  added to System functions table, cat description updated, stale rm
  Safety Wrapper entry and note removed
rootiest merged commit 0298e5a483 into main 2026-05-30 05:21:48 +00:00
rootiest deleted branch feat/scrollback-history-on-exit 2026-05-30 05:21:49 +00:00
Sign in to join this conversation.