From 72ff2e63161c5e8f6b15125873f20049fab381d1 Mon Sep 17 00:00:00 2001 From: Michael Housh Date: Thu, 9 Oct 2025 14:46:18 -0400 Subject: [PATCH] feat: Adds logs picker / views to utils-launcher --- env/.config/utils-launcher/config.json | 5 ++ .../scripts/hypr/utils/logs/logs-picker | 56 +++++++++++++++++++ runs/dev | 1 + 3 files changed, 62 insertions(+) create mode 100755 env/.local/scripts/hypr/utils/logs/logs-picker diff --git a/env/.config/utils-launcher/config.json b/env/.config/utils-launcher/config.json index 49192c8..64465b1 100644 --- a/env/.config/utils-launcher/config.json +++ b/env/.config/utils-launcher/config.json @@ -14,6 +14,11 @@ "description": "Clear the clipboard history file.", "exec": "$SCRIPTS/hypr/clear-clipboard-history --notify-complete" }, + { + "name": "Logs - view logs", + "description": "View logs generated by our custom commands.", + "exec": "$SCRIPTS/hypr/utils/logs/logs-picker" + }, { "name": "Monitors - stats / picker", "description": "View information from hyprctl about currently connected monitors.", diff --git a/env/.local/scripts/hypr/utils/logs/logs-picker b/env/.local/scripts/hypr/utils/logs/logs-picker new file mode 100755 index 0000000..b71190b --- /dev/null +++ b/env/.local/scripts/hypr/utils/logs/logs-picker @@ -0,0 +1,56 @@ +#!/usr/bin/env bash + +set -e +set -o nounset +set -o pipefail + +SCRIPTS=${SCRIPTS:-$HOME/.local/scripts} +THIS_FILE=${BASH_SOURCE[0]} +LOG_LABEL=$(basename "$THIS_FILE") +THIS=${THIS:-$LOG_LABEL} +LOG_FILE=${LOG_FILE:-"/tmp/$LOG_LABEL.log"} +FZF_DEFAULT_OPTS=${FZF_DEFAULT_OPTS:-""} + +# Logging utility function, use in place of echo. +log() { + logging log --source "$THIS_FILE" "$@" +} + +footer() { + cat <<'EOF' + __ + / / ___ ___ ____ + / /__/ _ \/ _ `(_-< +/____/\___/\_, /___/ + /___/ +EOF +} + +################################################################################ +# MAIN +################################################################################ + +# Setup logging file and label. +source "$SCRIPTS/hypr/logging" +setup-logging "$LOG_FILE" "$LOG_LABEL" + +# Setup colors before calling fzf. +[[ -z $FZF_DEFAULT_OPTS ]] && + [[ -f $SCRIPTS/catppuccin-colors ]] && + source $SCRIPTS/catppuccin-colors + +sel=$( + /bin/ls /tmp/*.log | + sed 's#.*/##; s/\..*$//' | # cleans to only show file name, excluding the path and '.log' + fzf --style=full \ + --footer="$(footer)" \ + --preview-label='[ Logs ]' \ + --preview='echo ""; bat /tmp/{}.log' \ + --preview-window="down" +) + +if [[ -z $sel ]]; then + log --error "No selection" && exit 1 +fi + +bat /tmp/$sel.log diff --git a/runs/dev b/runs/dev index 768fbca..06316b5 100755 --- a/runs/dev +++ b/runs/dev @@ -10,6 +10,7 @@ fi # Packages yay -S --noconfirm --needed \ + bat \ eza \ fastfetch \ fzf \