# Copyright (C) 2026 Rootiest # SPDX-License-Identifier: AGPL-3.0-or-later # # Generates ~/.local/bin/yay on first run (and on version bump) when # yay is installed. The wrapper runs yay in a PTY so progress # bars are preserved, renders the captured animation to a clean static log # (via scripts/clean_progress_log.py), and prunes old logs. # Auto-generating a wrapper in ~/.local/bin is opinionated (C2 auto-exec). # Wrapper generation is also gated by C5 (Logging & Capture). __fish_config_op_enabled __fish_config_op_autoexec; or return # C5 — Logging & Capture: remove generated wrapper and skip when logging is off if not __fish_config_op_enabled __fish_config_op_logging if test -f "$HOME/.local/bin/yay" and grep -q "# yay-wrapper-version:" "$HOME/.local/bin/yay" 2>/dev/null rm -f "$HOME/.local/bin/yay" end return end # Resolve the real yay binary, skipping our own shim (never /usr/bin-assumed). set -l _yay_real (__fish_real_command yay) set -l _yay_wrapper "$HOME/.local/bin/yay" set -l _yay_wrapper_version 6 # 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.' \ '# Runs yay in a PTY via script(1) so progress bars are preserved on screen,' \ '# then renders the captured terminal animation to a clean static log.' \ '' \ '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"' \ '' \ '# Build a safely-quoted command string for script(1).' \ '# script(1) allocates a PTY so yay detects a real terminal and shows progress.' \ "cmd_str=\"$_yay_real\"" \ 'for arg in "$@"; do' \ ' cmd_str+=" $(printf '"'"'%q'"'"' "$arg")"' \ 'done' \ 'script -q -e -c "$cmd_str" "$log_file"' \ 'exit_code=$?' \ '' \ '# Render the captured terminal animation (progress bars repaint in place via' \ '# cursor moves) down to its final static frame, preserving ANSI color. Falls' \ '# back to dropping only the script(1) header/footer when python3 is missing.' \ 'cleaner="${XDG_CONFIG_HOME:-$HOME/.config}/fish/scripts/clean_progress_log.py"' \ 'if command -v python3 >/dev/null 2>&1 && [[ -f "$cleaner" ]]; then' \ ' python3 "$cleaner" < "$log_file" > "${log_file}.tmp" 2>/dev/null && mv "${log_file}.tmp" "$log_file" || rm -f "${log_file}.tmp"' \ 'else' \ ' sed -i "/^Script \(started\|done\) on /d" "$log_file" 2>/dev/null || true' \ 'fi' \ '' \ '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' \ '' \ 'exit $exit_code' \ > $_yay_wrapper chmod +x $_yay_wrapper set --erase _yay_real _yay_wrapper _yay_wrapper_version