Files
fish-config/functions/cat.fish
T
rootiest 378cb6b221 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
2026-05-30 01:20:40 -04:00

33 lines
1.1 KiB
Fish

# Copyright (C) 2026 Rootiest
# 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, 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]
if test -d $argv[1]
# If it's a directory, run your custom ls function
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
if type -q bat
bat --plain --no-pager $argv
else
command cat $argv
end
end