Merge pull request 'feat(shell): enhance log browser, add yay wrapper, and integrate starship OSC prompt markers' (#26) from feat/log-browser-yay-ov-and-starship-osc into main
Reviewed-on: #26
This commit was merged in pull request #26.
This commit is contained in:
@@ -52,6 +52,8 @@ This config layers on top of the CachyOS base Fish configuration and adds:
|
||||
│ ├── done.fish # Done plugin (desktop notifications for long commands)
|
||||
│ ├── tricks.fish # PATH, bang-bang helpers, bat man pages, system aliases, history/backup utilities
|
||||
│ ├── paru-wrapper.fish # Auto-generates ~/.local/bin/paru logging wrapper on first run
|
||||
│ ├── yay-wrapper.fish # Auto-generates ~/.local/bin/yay logging wrapper on first run
|
||||
│ ├── starship.fish # fish_prompt with OSC 133;A/B shell-integration markers
|
||||
│ ├── wakatime.fish # WakaTime shell hook
|
||||
│ └── zoxide.fish # Zoxide z/zi aliases
|
||||
├── functions/ # Custom functions (one per file)
|
||||
@@ -89,7 +91,9 @@ Fisher and all listed plugins are installed automatically by the bootstrap scrip
|
||||
|
||||
### Starship
|
||||
|
||||
The primary prompt is [Starship](https://starship.rs/), initialized in `config.fish`. Configure it via `~/.config/starship.toml`.
|
||||
The primary prompt is [Starship](https://starship.rs/), managed via `conf.d/starship.fish`. Configure it via `~/.config/starship.toml`.
|
||||
|
||||
`conf.d/starship.fish` defines a `fish_prompt` wrapper that only activates when `starship` is in `PATH`. It emits OSC 133;A (prompt start) immediately before Starship renders and OSC 133;B (input start) immediately after, placing both markers on the prompt line itself rather than on the blank line above it. This enables `ov` to use them as sticky section headers when browsing scrollback logs. Without Starship, fish's built-in prompt already handles these markers correctly with no wrapper needed.
|
||||
|
||||
### FZF
|
||||
|
||||
@@ -175,6 +179,10 @@ Desktop notifications for long-running commands via [franciscolourenco/done](htt
|
||||
|
||||
When running inside Kitty, closing a shell session with `exit` automatically saves a timestamped scrollback snapshot to `SCROLLBACK_HISTORY_DIR` (default: `~/.terminal_history`). Snapshots are named `scrollback_YYYY-MM-DD_HH-MM-SS.log` and the oldest files are pruned automatically once the count exceeds `SCROLLBACK_HISTORY_MAX_FILES`.
|
||||
|
||||
The `paru` and `yay` wrappers (auto-generated in `~/.local/bin/` by `conf.d/paru-wrapper.fish` and `conf.d/yay-wrapper.fish`) tee all AUR helper output to timestamped log files (`paru_YYYY-MM-DD_HH-MM-SS.log` / `yay_YYYY-MM-DD_HH-MM-SS.log`) in the same directory.
|
||||
|
||||
Before pruning to the max-files limit — and before displaying the log browser — junk logs are automatically removed by `_scrollback_prune_junk`: empty files, files with only a single meaningful line (e.g. bare `[exited]` captures), and Kitty tab-rename prompt captures are all silently discarded.
|
||||
|
||||
Use `exit --no-log` (or `exit -n`) to close without saving.
|
||||
|
||||
The `cat` function detects files inside `SCROLLBACK_HISTORY_DIR` (and any file containing raw ANSI escape sequences) and pipes them through `command cat` instead of `bat`, preserving color output.
|
||||
@@ -284,7 +292,7 @@ rm -f file.txt # Falls through to standard rm -f
|
||||
| `gitui` | Fast terminal Git UI |
|
||||
| `gi` | Generate and append `.gitignore` patterns from gitignore.io; `gi` (no args) appends boilerplate then prompts interactively; `gi <targets>` appends named patterns; `gi -s <targets>` prints to stdout; `gi -l` lists all targets |
|
||||
|
||||
### Package Management (Arch / paru)
|
||||
### Package Management (Arch / paru / yay)
|
||||
|
||||
| Function | Description |
|
||||
|---|---|
|
||||
@@ -293,6 +301,8 @@ rm -f file.txt # Falls through to standard rm -f
|
||||
| `upgrade` | Full system upgrade: `paru -Syu --noconfirm` |
|
||||
| `cleanup` | Log and remove orphaned packages |
|
||||
|
||||
`conf.d/paru-wrapper.fish` and `conf.d/yay-wrapper.fish` auto-generate thin wrapper scripts at `~/.local/bin/paru` and `~/.local/bin/yay` on first shell start (when the respective AUR helper is installed). These wrappers tee all output to timestamped log files in `SCROLLBACK_HISTORY_DIR` and prune old logs to stay under `SCROLLBACK_HISTORY_MAX_FILES`.
|
||||
|
||||
### Dependency Management
|
||||
|
||||
`fish-deps` is a unified command for checking, installing, and updating all tools this config depends on.
|
||||
@@ -356,8 +366,8 @@ Install method priority: **git+cargo source build** (fish) → **cargo** (other
|
||||
| `wake-lock <cmd>` | Run a command with `systemd-inhibit` to prevent sleep |
|
||||
| `swapstat` | Colorized zRAM compression ratio, swappiness, and swap priority report |
|
||||
| `sudo-toggle` | Toggle sudo password bypass — writes/clears a `NOPASSWD` rule in `/etc/sudoers.d/nofail-toggle` |
|
||||
| `smart_exit` | Captures Kitty terminal scrollback to a timestamped log on exit; `--no-log` skips capture; auto-prunes oldest logs when count exceeds `SCROLLBACK_HISTORY_MAX_FILES` |
|
||||
| `logs` | Browse terminal log files (scrollback and paru) interactively with fzf; `Enter` opens in `$PAGER`, `Ctrl-E` opens in `$EDITOR`; `-c <category>` filters to `scrollback` or `paru` |
|
||||
| `smart_exit` | Captures Kitty terminal scrollback to a timestamped log on exit; `--no-log` skips capture; runs `_scrollback_prune_junk` then auto-prunes oldest logs when count exceeds `SCROLLBACK_HISTORY_MAX_FILES` |
|
||||
| `logs` | Browse scrollback, paru, and yay log files interactively with fzf; `Enter` opens in `$PAGER`, `Ctrl-E` opens in `$EDITOR`, `Ctrl-D` deletes (with Y/n confirm), `?` toggles a keybind help overlay; `-c <category>` filters to `scrollback`, `paru`, or `yay`; paru/yay logs open in `ov` with syntax highlights and sticky section headers; scrollback logs open in `ov` with per-command sticky prompt headers via OSC 133;A markers |
|
||||
| `psmem` | List all processes sorted by memory usage (descending) |
|
||||
| `psmem10` | Top 10 processes by memory usage |
|
||||
| `tmux-clean` | Kill all detached tmux sessions |
|
||||
@@ -665,6 +675,9 @@ Then open a new Fish shell — Fisher and all plugins will be installed automati
|
||||
|
||||
A [chezmoi](https://www.chezmoi.io/) dotfile manager is also configured — secrets are sourced from `~/.config/.user-dots/fish/secrets.fish` and excluded from version control.
|
||||
|
||||
> [!IMPORTANT]
|
||||
> `config.fish` ends with a bare `return` statement. This intentionally prevents any lines appended **after** that point from executing. Many tools (starship, zoxide, mise, etc.) offer a setup command that appends an `init | source` line to your `config.fish` — those lines will silently have no effect here. All integrations are managed through `conf.d/` files instead. If you add a new tool and its shell integration appears to do nothing, check whether it appended an init line to the bottom of `config.fish` and create a `conf.d/<tool>.fish` file for it instead.
|
||||
|
||||
---
|
||||
## Personalization
|
||||
|
||||
|
||||
@@ -0,0 +1,235 @@
|
||||
# fish completion for ov -*- shell-script -*-
|
||||
|
||||
function __ov_debug
|
||||
set -l file "$BASH_COMP_DEBUG_FILE"
|
||||
if test -n "$file"
|
||||
echo "$argv" >> $file
|
||||
end
|
||||
end
|
||||
|
||||
function __ov_perform_completion
|
||||
__ov_debug "Starting __ov_perform_completion"
|
||||
|
||||
# Extract all args except the last one
|
||||
set -l args (commandline -opc)
|
||||
# Extract the last arg and escape it in case it is a space
|
||||
set -l lastArg (string escape -- (commandline -ct))
|
||||
|
||||
__ov_debug "args: $args"
|
||||
__ov_debug "last arg: $lastArg"
|
||||
|
||||
# Disable ActiveHelp which is not supported for fish shell
|
||||
set -l requestComp "OV_ACTIVE_HELP=0 $args[1] __complete $args[2..-1] $lastArg"
|
||||
|
||||
__ov_debug "Calling $requestComp"
|
||||
set -l results (eval $requestComp 2> /dev/null)
|
||||
|
||||
# Some programs may output extra empty lines after the directive.
|
||||
# Let's ignore them or else it will break completion.
|
||||
# Ref: https://github.com/spf13/cobra/issues/1279
|
||||
for line in $results[-1..1]
|
||||
if test (string trim -- $line) = ""
|
||||
# Found an empty line, remove it
|
||||
set results $results[1..-2]
|
||||
else
|
||||
# Found non-empty line, we have our proper output
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
set -l comps $results[1..-2]
|
||||
set -l directiveLine $results[-1]
|
||||
|
||||
# For Fish, when completing a flag with an = (e.g., <program> -n=<TAB>)
|
||||
# completions must be prefixed with the flag
|
||||
set -l flagPrefix (string match -r -- '-.*=' "$lastArg")
|
||||
|
||||
__ov_debug "Comps: $comps"
|
||||
__ov_debug "DirectiveLine: $directiveLine"
|
||||
__ov_debug "flagPrefix: $flagPrefix"
|
||||
|
||||
for comp in $comps
|
||||
printf "%s%s\n" "$flagPrefix" "$comp"
|
||||
end
|
||||
|
||||
printf "%s\n" "$directiveLine"
|
||||
end
|
||||
|
||||
# this function limits calls to __ov_perform_completion, by caching the result behind $__ov_perform_completion_once_result
|
||||
function __ov_perform_completion_once
|
||||
__ov_debug "Starting __ov_perform_completion_once"
|
||||
|
||||
if test -n "$__ov_perform_completion_once_result"
|
||||
__ov_debug "Seems like a valid result already exists, skipping __ov_perform_completion"
|
||||
return 0
|
||||
end
|
||||
|
||||
set --global __ov_perform_completion_once_result (__ov_perform_completion)
|
||||
if test -z "$__ov_perform_completion_once_result"
|
||||
__ov_debug "No completions, probably due to a failure"
|
||||
return 1
|
||||
end
|
||||
|
||||
__ov_debug "Performed completions and set __ov_perform_completion_once_result"
|
||||
return 0
|
||||
end
|
||||
|
||||
# this function is used to clear the $__ov_perform_completion_once_result variable after completions are run
|
||||
function __ov_clear_perform_completion_once_result
|
||||
__ov_debug ""
|
||||
__ov_debug "========= clearing previously set __ov_perform_completion_once_result variable =========="
|
||||
set --erase __ov_perform_completion_once_result
|
||||
__ov_debug "Successfully erased the variable __ov_perform_completion_once_result"
|
||||
end
|
||||
|
||||
function __ov_requires_order_preservation
|
||||
__ov_debug ""
|
||||
__ov_debug "========= checking if order preservation is required =========="
|
||||
|
||||
__ov_perform_completion_once
|
||||
if test -z "$__ov_perform_completion_once_result"
|
||||
__ov_debug "Error determining if order preservation is required"
|
||||
return 1
|
||||
end
|
||||
|
||||
set -l directive (string sub --start 2 $__ov_perform_completion_once_result[-1])
|
||||
__ov_debug "Directive is: $directive"
|
||||
|
||||
set -l shellCompDirectiveKeepOrder 32
|
||||
set -l keeporder (math (math --scale 0 $directive / $shellCompDirectiveKeepOrder) % 2)
|
||||
__ov_debug "Keeporder is: $keeporder"
|
||||
|
||||
if test $keeporder -ne 0
|
||||
__ov_debug "This does require order preservation"
|
||||
return 0
|
||||
end
|
||||
|
||||
__ov_debug "This doesn't require order preservation"
|
||||
return 1
|
||||
end
|
||||
|
||||
|
||||
# This function does two things:
|
||||
# - Obtain the completions and store them in the global __ov_comp_results
|
||||
# - Return false if file completion should be performed
|
||||
function __ov_prepare_completions
|
||||
__ov_debug ""
|
||||
__ov_debug "========= starting completion logic =========="
|
||||
|
||||
# Start fresh
|
||||
set --erase __ov_comp_results
|
||||
|
||||
__ov_perform_completion_once
|
||||
__ov_debug "Completion results: $__ov_perform_completion_once_result"
|
||||
|
||||
if test -z "$__ov_perform_completion_once_result"
|
||||
__ov_debug "No completion, probably due to a failure"
|
||||
# Might as well do file completion, in case it helps
|
||||
return 1
|
||||
end
|
||||
|
||||
set -l directive (string sub --start 2 $__ov_perform_completion_once_result[-1])
|
||||
set --global __ov_comp_results $__ov_perform_completion_once_result[1..-2]
|
||||
|
||||
__ov_debug "Completions are: $__ov_comp_results"
|
||||
__ov_debug "Directive is: $directive"
|
||||
|
||||
set -l shellCompDirectiveError 1
|
||||
set -l shellCompDirectiveNoSpace 2
|
||||
set -l shellCompDirectiveNoFileComp 4
|
||||
set -l shellCompDirectiveFilterFileExt 8
|
||||
set -l shellCompDirectiveFilterDirs 16
|
||||
|
||||
if test -z "$directive"
|
||||
set directive 0
|
||||
end
|
||||
|
||||
set -l compErr (math (math --scale 0 $directive / $shellCompDirectiveError) % 2)
|
||||
if test $compErr -eq 1
|
||||
__ov_debug "Received error directive: aborting."
|
||||
# Might as well do file completion, in case it helps
|
||||
return 1
|
||||
end
|
||||
|
||||
set -l filefilter (math (math --scale 0 $directive / $shellCompDirectiveFilterFileExt) % 2)
|
||||
set -l dirfilter (math (math --scale 0 $directive / $shellCompDirectiveFilterDirs) % 2)
|
||||
if test $filefilter -eq 1; or test $dirfilter -eq 1
|
||||
__ov_debug "File extension filtering or directory filtering not supported"
|
||||
# Do full file completion instead
|
||||
return 1
|
||||
end
|
||||
|
||||
set -l nospace (math (math --scale 0 $directive / $shellCompDirectiveNoSpace) % 2)
|
||||
set -l nofiles (math (math --scale 0 $directive / $shellCompDirectiveNoFileComp) % 2)
|
||||
|
||||
__ov_debug "nospace: $nospace, nofiles: $nofiles"
|
||||
|
||||
# If we want to prevent a space, or if file completion is NOT disabled,
|
||||
# we need to count the number of valid completions.
|
||||
# To do so, we will filter on prefix as the completions we have received
|
||||
# may not already be filtered so as to allow fish to match on different
|
||||
# criteria than the prefix.
|
||||
if test $nospace -ne 0; or test $nofiles -eq 0
|
||||
set -l prefix (commandline -t | string escape --style=regex)
|
||||
__ov_debug "prefix: $prefix"
|
||||
|
||||
set -l completions (string match -r -- "^$prefix.*" $__ov_comp_results)
|
||||
set --global __ov_comp_results $completions
|
||||
__ov_debug "Filtered completions are: $__ov_comp_results"
|
||||
|
||||
# Important not to quote the variable for count to work
|
||||
set -l numComps (count $__ov_comp_results)
|
||||
__ov_debug "numComps: $numComps"
|
||||
|
||||
if test $numComps -eq 1; and test $nospace -ne 0
|
||||
# We must first split on \t to get rid of the descriptions to be
|
||||
# able to check what the actual completion will be.
|
||||
# We don't need descriptions anyway since there is only a single
|
||||
# real completion which the shell will expand immediately.
|
||||
set -l split (string split --max 1 \t $__ov_comp_results[1])
|
||||
|
||||
# Fish won't add a space if the completion ends with any
|
||||
# of the following characters: @=/:.,
|
||||
set -l lastChar (string sub -s -1 -- $split)
|
||||
if not string match -r -q "[@=/:.,]" -- "$lastChar"
|
||||
# In other cases, to support the "nospace" directive we trick the shell
|
||||
# by outputting an extra, longer completion.
|
||||
__ov_debug "Adding second completion to perform nospace directive"
|
||||
set --global __ov_comp_results $split[1] $split[1].
|
||||
__ov_debug "Completions are now: $__ov_comp_results"
|
||||
end
|
||||
end
|
||||
|
||||
if test $numComps -eq 0; and test $nofiles -eq 0
|
||||
# To be consistent with bash and zsh, we only trigger file
|
||||
# completion when there are no other completions
|
||||
__ov_debug "Requesting file completion"
|
||||
return 1
|
||||
end
|
||||
end
|
||||
|
||||
return 0
|
||||
end
|
||||
|
||||
# Since Fish completions are only loaded once the user triggers them, we trigger them ourselves
|
||||
# so we can properly delete any completions provided by another script.
|
||||
# Only do this if the program can be found, or else fish may print some errors; besides,
|
||||
# the existing completions will only be loaded if the program can be found.
|
||||
if type -q "ov"
|
||||
# The space after the program name is essential to trigger completion for the program
|
||||
# and not completion of the program name itself.
|
||||
# Also, we use '> /dev/null 2>&1' since '&>' is not supported in older versions of fish.
|
||||
complete --do-complete "ov " > /dev/null 2>&1
|
||||
end
|
||||
|
||||
# Remove any pre-existing completions for the program since we will be handling all of them.
|
||||
complete -c ov -e
|
||||
|
||||
# this will get called after the two calls below and clear the $__ov_perform_completion_once_result global
|
||||
complete -c ov -n '__ov_clear_perform_completion_once_result'
|
||||
# The call to __ov_prepare_completions will setup __ov_comp_results
|
||||
# which provides the program's completion choices.
|
||||
# If this doesn't require order preservation, we don't use the -k flag
|
||||
complete -c ov -n 'not __ov_requires_order_preservation && __ov_prepare_completions' -f -a '$__ov_comp_results'
|
||||
# otherwise we use the -k flag
|
||||
complete -k -c ov -n '__ov_requires_order_preservation && __ov_prepare_completions' -f -a '$__ov_comp_results'
|
||||
@@ -0,0 +1,26 @@
|
||||
# Copyright (C) 2026 Rootiest
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
#
|
||||
# Defines fish_prompt only when starship is installed.
|
||||
# Without starship, fish's built-in prompt already emits OSC 133;A
|
||||
# on the prompt line itself, so no wrapper is needed.
|
||||
|
||||
type -q starship; or return
|
||||
|
||||
function fish_prompt
|
||||
set -l last_status $status
|
||||
|
||||
# Blank line between output and next prompt, skipped at the top of a cleared screen
|
||||
if not test "$fish_private_mode" = true; and test (commandline) = ""
|
||||
echo
|
||||
end
|
||||
|
||||
# OSC 133;A here (after the blank line) puts the marker on the prompt line itself,
|
||||
# not the blank line — required for ov's section-delimiter to pin the right line.
|
||||
printf "\x1b]133;A\x07"
|
||||
|
||||
set -g STARSHIP_CMD_STATUS $last_status
|
||||
command starship prompt --status=$last_status --pipestatus=$pipestatus --jobs=(count (jobs -p))
|
||||
|
||||
printf "\x1b]133;B\x07"
|
||||
end
|
||||
@@ -0,0 +1,47 @@
|
||||
# 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.
|
||||
|
||||
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
|
||||
+5
-6
@@ -172,12 +172,6 @@ if status is-interactive
|
||||
# Helps ensure that Claude Code's terminal output is clean and doesn't have flickering issues.
|
||||
set -gx CLAUDE_CODE_NO_FLICKER 1
|
||||
|
||||
# ─────────────────────────── Starship prompt ────────────────────────────
|
||||
# Initializes the Starship prompt, which provides a highly customizable and informative command prompt.
|
||||
# This is wrapped in a check to ensure that it only runs if Starship is installed,
|
||||
# preventing errors if it's not available.
|
||||
type -q starship; and starship init fish | source
|
||||
|
||||
# ╭────────────────────────────── OVERRIDES ─────────────────────────────╮
|
||||
# | Run these last so they can override any previous settings. |
|
||||
# | This is useful for machine-specific behavior or configurations. |
|
||||
@@ -204,3 +198,8 @@ if status is-interactive
|
||||
# | End of override section. |
|
||||
# ╰──────────────────────────── END OVERRIDES ──────────────────────────╯
|
||||
end
|
||||
|
||||
# Tools like starship, zoxide, etc. append init lines below this point via their
|
||||
# setup commands. We manage all integrations through conf.d/ instead, so we
|
||||
# return here to prevent injected lines from conflicting with that setup.
|
||||
return
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
# Copyright (C) 2026 Rootiest
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
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 rm $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
|
||||
rm $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'
|
||||
rm $f
|
||||
end
|
||||
end
|
||||
end
|
||||
+68
-5
@@ -18,11 +18,12 @@ function logs --description 'Browse terminal log files interactively with fzf'
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " "$c_primary"-h, --help"$c_reset" Show this help"
|
||||
echo " "$c_primary"-c, --category"$c_reset" Limit to one category: scrollback, paru"
|
||||
echo " "$c_primary"-c, --category"$c_reset" Limit to one category: scrollback, paru, yay"
|
||||
echo ""
|
||||
echo "Keys in fzf:"
|
||||
echo " "$c_primary"Enter"$c_reset" Open in \$PAGER"
|
||||
echo " "$c_primary"Ctrl-E"$c_reset" Open in \$EDITOR"
|
||||
echo " "$c_primary"Ctrl-D"$c_reset" Delete selected log"
|
||||
echo " "$c_primary"Ctrl-C"$c_reset" Quit"
|
||||
return 0
|
||||
end
|
||||
@@ -37,6 +38,11 @@ function logs --description 'Browse terminal log files interactively with fzf'
|
||||
set -a scan_dirs $legacy_dir
|
||||
end
|
||||
|
||||
# Strip junk scrollback logs before building the file list
|
||||
for dir in $scan_dirs
|
||||
_scrollback_prune_junk $dir
|
||||
end
|
||||
|
||||
# Collect entries: "SORTKEY|FILEPATH|CATEGORY"
|
||||
set -l entries
|
||||
for dir in $scan_dirs
|
||||
@@ -78,26 +84,83 @@ function logs --description 'Browse terminal log files interactively with fzf'
|
||||
set label (printf '\033[36m[scrollback]\033[0m')
|
||||
case paru
|
||||
set label (printf '\033[32m[paru ]\033[0m')
|
||||
case yay
|
||||
set label (printf '\033[33m[yay ]\033[0m')
|
||||
end
|
||||
|
||||
set -a fzf_lines (printf '%s\t%s %s %s' $parts[2] $date $time $label)
|
||||
end
|
||||
|
||||
set -l selected (printf '%s\n' $fzf_lines | fzf \
|
||||
set -l tmpfile (mktemp)
|
||||
set -l helpfile (mktemp)
|
||||
set -l togglescript (mktemp)
|
||||
set -l deletescript (mktemp)
|
||||
set -l helpflag "$tmpfile.help"
|
||||
printf '%s\n' $fzf_lines > $tmpfile
|
||||
printf 'Terminal Logs — Key Bindings\n\n Enter View selected log in pager\n Ctrl-E Edit selected log in editor\n Ctrl-D Delete selected log\n Ctrl-C Quit\n ? Toggle this help\n\nFiltering:\n Type to fuzzy-filter by date or category\n Use -c flag to limit: scrollback, paru, yay' > $helpfile
|
||||
# Help toggle script — avoids nested parens inside transform()
|
||||
printf '#!/bin/sh\nif test -f %s; then\n rm -f %s\n printf "change-preview(command cat {1})"\nelse\n touch %s\n printf "change-preview(command cat %s)"\nfi\n' \
|
||||
$helpflag $helpflag $helpflag $helpfile > $togglescript
|
||||
chmod +x $togglescript
|
||||
# Delete confirmation script — avoids nested parens inside execute(), and ensures
|
||||
# tmpfile is updated before +reload fires (execute is synchronous, execute-silent is not)
|
||||
printf '%s\n' \
|
||||
'#!/bin/sh' \
|
||||
'FILE="$1"' \
|
||||
'printf "Delete %s? [Y/n] " "$(basename "$FILE")"' \
|
||||
'read confirm' \
|
||||
'case "$confirm" in [nN]) exit 0 ;; esac' \
|
||||
"fish -c \"rm \$FILE\"" \
|
||||
"grep -vF \"\$FILE\" $tmpfile > $tmpfile.new" \
|
||||
"mv $tmpfile.new $tmpfile" \
|
||||
> $deletescript
|
||||
chmod +x $deletescript
|
||||
|
||||
set -l selected (command cat $tmpfile | fzf \
|
||||
--ansi \
|
||||
--delimiter '\t' \
|
||||
--with-nth 2 \
|
||||
--preview 'command cat {1}' \
|
||||
--preview-window 'right:60%:wrap' \
|
||||
--prompt 'Terminal Logs -> ' \
|
||||
--header 'Enter: View Ctrl-E: Edit Ctrl-C: Quit (type to filter by date or category)' \
|
||||
--bind "ctrl-e:execute($editor {1})")
|
||||
--header '?: Help Enter: View Ctrl-E: Edit Ctrl-D: Delete Ctrl-C: Quit' \
|
||||
--bind "ctrl-e:execute($editor {1})" \
|
||||
--bind "ctrl-d:execute($deletescript {1})+reload(command cat $tmpfile)" \
|
||||
--bind "?:transform($togglescript)")
|
||||
|
||||
rm -f $tmpfile $tmpfile.new $helpfile $helpflag $togglescript $deletescript
|
||||
|
||||
test -n "$selected" || return 0
|
||||
|
||||
set -l file (echo $selected | cut -f1)
|
||||
test -f $file || return 1
|
||||
if command -q $PAGER
|
||||
|
||||
set -l base (basename $file)
|
||||
|
||||
# 1. Maintain base multi-color parsing highlights
|
||||
set -l paru_flags -M "^\s*:: .*,upgrading \S+,downloading\.\.\.,\(\s*\d+/\d+\),(Total.*Size:|Net Upgrade Size:|\s*Package \(\d+\))"
|
||||
|
||||
set -l use_ov 0
|
||||
if command -q ov
|
||||
if not set -q PAGER; or test "$PAGER" = ov
|
||||
set use_ov 1
|
||||
end
|
||||
end
|
||||
|
||||
if test $use_ov -eq 1
|
||||
if string match -qr '^(paru|yay)' $base
|
||||
set -l section_regex '^\s*Package \(\d+\)|^\s*:: (Proceed|Retrieving|Running pre-transaction|Processing package changes|Running post-transaction|Looking for .* upgrades\.\.\.)|^\s*==>'
|
||||
set paru_flags $paru_flags --section-delimiter $section_regex --section-header -c
|
||||
command ov $paru_flags $file
|
||||
else if string match -qr '^scrollback' $base
|
||||
# OSC 133;A (prompt start) appears on its own invisible line immediately before
|
||||
# the rendered prompt. --section-header-num 2 captures both that blank marker
|
||||
# line and the actual prompt line as the sticky header, making the prompt visible.
|
||||
command ov --section-delimiter '\x1b\]133;A' --section-header --section-header-num 1 $file
|
||||
else
|
||||
command ov $file
|
||||
end
|
||||
else if set -q PAGER; and command -q $PAGER
|
||||
command cat $file | command $PAGER
|
||||
else
|
||||
command cat $file
|
||||
|
||||
@@ -50,7 +50,10 @@ function smart_exit --description 'Capture colorized scrollback before exiting,
|
||||
end
|
||||
end
|
||||
|
||||
# 4. Automatic Pruning Logic
|
||||
# 4. Prune junk logs before counting toward the max
|
||||
_scrollback_prune_junk $snapshot_dir
|
||||
|
||||
# 5. Automatic Pruning Logic
|
||||
set -l current_logs $snapshot_dir/scrollback_*.log
|
||||
if test -f "$current_logs[1]"
|
||||
set -l total_files (count $current_logs)
|
||||
|
||||
Reference in New Issue
Block a user