From 5946a177fb0d23c0f35d5070e90a65b9cc510219 Mon Sep 17 00:00:00 2001 From: Michael Housh Date: Mon, 6 Oct 2025 18:46:59 -0400 Subject: [PATCH] feat: Adds help to preview-stats, changes message that get logs to console during error or warning messages. --- env/.local/scripts/hypr/logging | 2 +- env/.local/scripts/hypr/preview-stats | 52 +++++++++++++-------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/env/.local/scripts/hypr/logging b/env/.local/scripts/hypr/logging index d16f0fa..d278608 100755 --- a/env/.local/scripts/hypr/logging +++ b/env/.local/scripts/hypr/logging @@ -111,7 +111,7 @@ logging() { # Also log errors and warning messages to the console. if [[ $error_flag == "1" ]] || [[ $warn_flag == "1" ]]; then - echo -e "[id: $LOG_INVOCATION_ID]: $msg" + echo -e "[id: $LOG_INVOCATION_ID]$msg" fi else # Dry run mode, so just log to the console diff --git a/env/.local/scripts/hypr/preview-stats b/env/.local/scripts/hypr/preview-stats index 34994c3..a596fc1 100755 --- a/env/.local/scripts/hypr/preview-stats +++ b/env/.local/scripts/hypr/preview-stats @@ -34,6 +34,18 @@ log() { logging log --source "$THIS_FILE" "$@" } +call_jq() { + hypr_path=$1 + select_str=$2 + optional_keys=$3 + + if [[ -n $optional_keys ]]; then + hyprctl $hypr_path -j | jq -C ".[] | $select_str | $optional_keys" + else + hyprctl $hypr_path -j | jq -C ".[] | $select_str" + fi +} + ################################################################################ # MAIN ################################################################################ @@ -42,39 +54,27 @@ log() { source "$SCRIPTS/hypr/logging" setup-logging "$THIS" -if [[ ! ${#@} -ge 2 ]]; then - log --error "Unexpected argument count: ${#@}, expected at least: 2" - usage && exit 1 +# Early out check for help flag +if [[ $@ =~ -h ]] || [[ $@ =~ --help ]]; then + usage && exit 0 +# Check for expected argument count or error. +elif [[ ! $# -ge 2 ]] || [[ $# -gt 3 ]]; then + log --error "Unexpected argument count, expected 2 or 3 but got '$#'" + exit 1 fi -mode="$1" -# Remove single quotes from the arg. -arg="${2//\'/}" +mode=$1 +arg=$2 +arg2=$3 # either optional keys or utils config. if [[ $mode == "monitor" ]]; then - keys="$3" - if [[ -n $keys ]]; then - hyprctl monitors -j | jq -C ".[] | select(.id == $arg) | $keys" - else - hyprctl monitors -j | jq -C ".[] | select(.id == $arg)" - fi + call_jq monitors "select(.id == $arg)" "$arg2" elif [[ $mode == "window" ]]; then - keys="$3" - if [[ -n $keys ]]; then - hyprctl clients -j | jq -C ".[] | select(.address == \"$arg\") | $keys" - else - hyprctl clients -j | jq -C ".[] | select(.address == \"$arg\")" - fi - + call_jq clients "select(.address == \"$arg\")" "$arg2" elif [[ $mode == "workspace" ]]; then - keys="$3" - if [[ -n $keys ]]; then - hyprctl workspaces -j | jq -C ".[] | select(.id == $arg) | $keys" - else - hyprctl workspaces -j | jq -C ".[] | select(.id == $arg)" - fi + call_jq workspaces "select(.id == $arg)" "$arg2" elif [[ $mode == "utils" ]]; then - config="${3//\'/}" + config="${arg2//\'/}" if [[ ! -f $config ]]; then log --error "No utility-launcher config found: $config" exit 1