feat(c5): prune old tmux logs and share pipe-pane helper

Extract the tmux pipe-pane setup into functions/_tmux_pipe_log.fish,
called by both conf.d/tmux-logging.fish (startup) and
__fish_config_sync_logging (C5 re-enable). The helper prunes the oldest
tmux_*.log files by mtime to stay within SCROLLBACK_HISTORY_MAX_FILES,
matching the paru/yay wrappers.

Uses 'command ls' to bypass the eza ls shadow, which injects OSC-8
hyperlink escapes into paths and corrupted the filenames passed to rm.
This commit is contained in:
2026-06-16 01:03:54 -04:00
parent 2e1750b5a4
commit b998cc652e
4 changed files with 50 additions and 16 deletions
+1 -7
View File
@@ -11,10 +11,4 @@ status is-interactive; or exit
type -q tmux; or exit type -q tmux; or exit
set -q TMUX; or exit set -q TMUX; or exit
set -l log_dir (set -q SCROLLBACK_HISTORY_DIR; and echo $SCROLLBACK_HISTORY_DIR; or echo "$HOME/.terminal_history") _tmux_pipe_log
set -l pane_id (tmux display-message -p '#{session_name}-w#{window_index}-p#{pane_index}' 2>/dev/null)
set -l timestamp (date "+%Y-%m-%d_%H-%M-%S")
set -l log_file "$log_dir/tmux_"$pane_id"_"$timestamp".log"
mkdir -p $log_dir
tmux pipe-pane "cat >> $log_file" 2>/dev/null
+3 -1
View File
@@ -1697,7 +1697,9 @@ The tmux capture starts automatically when fish launches inside any tmux
pane ($TMUX is set). It uses tmux's native pipe-pane to stream all pane pane ($TMUX is set). It uses tmux's native pipe-pane to stream all pane
output directly to disk without an intermediate process. Each fish shell output directly to disk without an intermediate process. Each fish shell
session gets its own log file; a new log is created on each shell start session gets its own log file; a new log is created on each shell start
(including exec fish and new splits). (including exec fish and new splits). Before each new log, the oldest
tmux_*.log files are pruned (by modification time) to keep the total within
SCROLLBACK_HISTORY_MAX_FILES, matching the paru/yay wrapper behaviour.
Logging coordination via sentinel file Logging coordination via sentinel file
+1 -8
View File
@@ -34,14 +34,7 @@ function __fish_config_sync_logging --description 'Sync C5 logging state: sentin
rm -f $sentinel rm -f $sentinel
# Restart tmux pipe-pane for the current pane if inside tmux # Restart tmux pipe-pane for the current pane if inside tmux
if set -q TMUX _tmux_pipe_log
set -l log_dir (set -q SCROLLBACK_HISTORY_DIR; and echo $SCROLLBACK_HISTORY_DIR; or echo "$HOME/.terminal_history")
set -l pane_id (tmux display-message -p '#{session_name}-w#{window_index}-p#{pane_index}' 2>/dev/null)
set -l timestamp (date "+%Y-%m-%d_%H-%M-%S")
set -l log_file "$log_dir/tmux_"$pane_id"_"$timestamp".log"
mkdir -p $log_dir
tmux pipe-pane "cat >> $log_file" 2>/dev/null
end
if test -x /usr/bin/paru if test -x /usr/bin/paru
mkdir -p (dirname $paru_wrapper) mkdir -p (dirname $paru_wrapper)
+45
View File
@@ -0,0 +1,45 @@
# Copyright (C) 2026 Rootiest
# SPDX-License-Identifier: AGPL-3.0-or-later
# SYNOPSIS
# _tmux_pipe_log
#
# DESCRIPTION
# Starts tmux pipe-pane capture for the current pane, streaming its output
# to a timestamped log in SCROLLBACK_HISTORY_DIR (default ~/.terminal_history).
# Before starting, prunes the oldest tmux_*.log files so that the total stays
# within SCROLLBACK_HISTORY_MAX_FILES (default 100), leaving room for the new
# log. No-op when not inside a tmux session ($TMUX unset) or tmux is missing.
# Shared by conf.d/tmux-logging.fish (shell startup) and
# __fish_config_sync_logging (C5 re-enable) so both stay in sync.
#
# RETURNS
# 0 Always
#
# EXAMPLE
# _tmux_pipe_log
function _tmux_pipe_log --description 'Start tmux pipe-pane capture for the current pane, with pruning'
set -q TMUX; or return 0
type -q tmux; or return 0
set -l log_dir (set -q SCROLLBACK_HISTORY_DIR; and echo $SCROLLBACK_HISTORY_DIR; or echo "$HOME/.terminal_history")
set -l max_files (set -q SCROLLBACK_HISTORY_MAX_FILES; and echo $SCROLLBACK_HISTORY_MAX_FILES; or echo 100)
set -l pane_id (tmux display-message -p '#{session_name}-w#{window_index}-p#{pane_index}' 2>/dev/null)
set -l timestamp (date "+%Y-%m-%d_%H-%M-%S")
set -l log_file "$log_dir/tmux_"$pane_id"_"$timestamp".log"
mkdir -p $log_dir
# Prune oldest logs, leaving room for the one we're about to create.
# Names carry a per-pane prefix, so sort by mtime (command ls -tr = oldest
# first). Use `command ls`: the bare `ls` is shadowed by the eza wrapper,
# which injects OSC-8 escapes into paths and corrupts the filenames.
set -l keep (math max 0, $max_files - 1)
set -l logs (command ls -1tr $log_dir/tmux_*.log 2>/dev/null)
if test (count $logs) -gt $keep
set -l excess (math (count $logs) - $keep)
command rm -f $logs[1..$excess]
end
tmux pipe-pane "cat >> $log_file" 2>/dev/null
end