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

- 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
This commit is contained in:
2026-05-30 01:20:40 -04:00
parent 9bff3f3c69
commit 378cb6b221
5 changed files with 114 additions and 7 deletions
+11 -1
View File
@@ -2,7 +2,7 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
# Use bat for files and ls for directories when using cat
function cat --wraps='bat' --description 'Use bat for files and ls for directories'
function cat --wraps='bat' --description 'Use bat for files, ls for directories, and raw cat for ANSI logs'
# If no arguments are provided, cat usually waits for stdin.
# We'll maintain that behavior by skipping the directory check if $argv is empty.
if set -q argv[1]
@@ -11,6 +11,16 @@ function cat --wraps='bat' --description 'Use bat for files and ls for directori
ls $argv
return
end
# NEW: Check if the target file lives in your scrollback snapshot directory OR
# contains raw terminal ANSI color escape sequences.
if test -f $argv[1]
if string match -q "$SCROLLBACK_HISTORY_DIR/*" $argv[1]
or string match -qr '\e\[[0-9;]*m' (head -n 5 $argv[1] 2>/dev/null)
command cat $argv
return
end
end
end
# Fallback to bat or standard cat