Verified an agy audit of every bare rm call (the trash-routing C1 shadow) by hand rather than trusting its report. Confirmed correct: scrub.fish's custom_rm strategy and logs.fish's Ctrl-D delete both deliberately want trash for a real, user-facing deletion. Confirmed and fixed three cases where a function's own throwaway scratch file was going to the user's trash instead of being wiped: fc.fish's edited-command tmpfile, dng2avif.fish's intermediate PNM (inconsistent with its own failure-path cleanup two lines up, which already used -f), and _scrollback_prune_junk.fish's junk log files (its sibling _prune_terminal_logs.fish already documents this exact pitfall in its header). Also went further than the report and classified every bypasses-shadow(rm) caller found by grep that had never been audited at all: config-settings.fish and edit.fish (own scratch cleanup, no destructive data at stake) and key-crypt.fish (--remove deletes the user's real input file after encryption, genuinely destructive, already documented in its own header as 'not a secure wipe'). Corrected scrub.fish's tag, which was missing uses-shadow(rm) for its deliberate trash-routing branch alongside the bypass branch it already had tagged. Added a note to the schema doc: rm's flag-based fallback lives inside the shadow itself, so a bare rm -f/rm -rf call is not the caller bypassing anything -- only an explicit command rm/builtin rm earns the tag. This is why dng2avif.fish's fix needed no CLASSIFICATION change: it already used rm -f, which was never actually the bug -- the missing -f on line 122 was.
52 lines
1.7 KiB
Fish
52 lines
1.7 KiB
Fish
# Copyright (C) 2026 Rootiest
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
# CLASSIFICATION
|
|
# bypasses-shadow(cat,rm), destructive
|
|
#
|
|
# SYNOPSIS
|
|
# _scrollback_prune_junk [dir]
|
|
#
|
|
# DESCRIPTION
|
|
# Removes low-value log files from the scrollback history directory:
|
|
# empty files, files with at most one meaningful line, and Kitty
|
|
# tab-rename prompt captures. Called by smart_exit.fish on session end.
|
|
#
|
|
# ARGUMENTS
|
|
# dir Directory to prune (defaults to $SCROLLBACK_HISTORY_DIR or
|
|
# ~/.terminal_history)
|
|
#
|
|
# EXAMPLE
|
|
# _scrollback_prune_junk ~/.terminal_history
|
|
function _scrollback_prune_junk --description 'Remove empty, trivial, and Kitty UI noise logs'
|
|
set -l dir (set -q SCROLLBACK_HISTORY_DIR; and echo $SCROLLBACK_HISTORY_DIR; or echo "$HOME/.terminal_history")
|
|
if set -q argv[1]
|
|
set dir $argv[1]
|
|
end
|
|
|
|
test -d $dir || return 0
|
|
|
|
# Remove any completely empty log file regardless of source
|
|
for f in $dir/*.log $dir/*.txt
|
|
test -f $f || continue
|
|
not test -s $f; and command rm -f $f
|
|
end
|
|
|
|
# Remove any log with only a single meaningful line (e.g. [exited], a lone prompt, or a trivial error)
|
|
for f in $dir/*.log $dir/*.txt
|
|
test -f $f || continue
|
|
set -l line_count (command cat $f | sed 's/\x1b\[[0-9;:]*[a-zA-Z]//g' | grep -cv '^\s*$')
|
|
if test $line_count -le 1
|
|
command rm -f $f
|
|
end
|
|
end
|
|
|
|
# Remove scrollback logs that are Kitty tab-rename prompts (UI noise, not real sessions)
|
|
for f in $dir/scrollback_*.log $dir/scrollback_*.txt
|
|
test -f $f || continue
|
|
if command cat $f | sed 's/\x1b\[[0-9;:]*[a-zA-Z]//g' | grep -q 'Enter the new title for this tab below'
|
|
command rm -f $f
|
|
end
|
|
end
|
|
end
|