# Copyright (C) 2026 Rootiest # SPDX-License-Identifier: AGPL-3.0-or-later # # Generates ~/.local/bin/yay on first run (and on version bump) when # /usr/bin/yay is installed. The wrapper tees yay output to a # timestamped log file and prunes old logs, mirroring smart_exit behavior. # Auto-generating a wrapper in ~/.local/bin is opinionated (C2 auto-exec). # Task #4's __fish_config_enable_logging will additionally gate this wrapper. __fish_config_op_enabled __fish_config_op_autoexec; or return set -l _yay_real /usr/bin/yay set -l _yay_wrapper "$HOME/.local/bin/yay" set -l _yay_wrapper_version 1 # Skip entirely if the real yay binary isn't present test -x $_yay_real; or return # Check if wrapper already exists at the expected version if test -f $_yay_wrapper and grep -q "# yay-wrapper-version: $_yay_wrapper_version" $_yay_wrapper 2>/dev/null set --erase _yay_real _yay_wrapper _yay_wrapper_version return end mkdir -p (dirname $_yay_wrapper) printf '%s\n' \ '#!/usr/bin/env bash' \ "# yay-wrapper-version: $_yay_wrapper_version" \ '# Auto-generated by conf.d/yay-wrapper.fish — do not edit by hand.' \ '# Tees yay output to a timestamped log file and prunes old ones.' \ 'set -o pipefail' \ '' \ 'log_dir="${SCROLLBACK_HISTORY_DIR:-$HOME/.terminal_history}"' \ 'mkdir -p "$log_dir"' \ 'log_file="$log_dir/yay_$(date +%Y-%m-%d_%H-%M-%S).log"' \ '' \ '/usr/bin/yay "$@" 2>&1 | tee "$log_file"' \ '' \ 'max_files="${SCROLLBACK_HISTORY_MAX_FILES:-100}"' \ 'mapfile -t logs < <(ls -1t "$log_dir"/yay_*.log 2>/dev/null)' \ 'excess=$(( ${#logs[@]} - max_files ))' \ 'for (( i = ${#logs[@]} - 1; i >= ${#logs[@]} - excess && i >= 0; i-- )); do' \ ' rm -f "${logs[$i]}"' \ 'done' \ > $_yay_wrapper chmod +x $_yay_wrapper set --erase _yay_real _yay_wrapper _yay_wrapper_version