feat: Adds help to preview-stats, changes message that get logs to console during error or warning messages.

This commit is contained in:
2025-10-06 18:46:59 -04:00
parent 7c08fec16b
commit 5946a177fb
2 changed files with 27 additions and 27 deletions

View File

@@ -111,7 +111,7 @@ logging() {
# Also log errors and warning messages to the console. # Also log errors and warning messages to the console.
if [[ $error_flag == "1" ]] || [[ $warn_flag == "1" ]]; then if [[ $error_flag == "1" ]] || [[ $warn_flag == "1" ]]; then
echo -e "[id: $LOG_INVOCATION_ID]: $msg" echo -e "[id: $LOG_INVOCATION_ID]$msg"
fi fi
else else
# Dry run mode, so just log to the console # Dry run mode, so just log to the console

View File

@@ -34,6 +34,18 @@ log() {
logging log --source "$THIS_FILE" "$@" 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 # MAIN
################################################################################ ################################################################################
@@ -42,39 +54,27 @@ log() {
source "$SCRIPTS/hypr/logging" source "$SCRIPTS/hypr/logging"
setup-logging "$THIS" setup-logging "$THIS"
if [[ ! ${#@} -ge 2 ]]; then # Early out check for help flag
log --error "Unexpected argument count: ${#@}, expected at least: 2" if [[ $@ =~ -h ]] || [[ $@ =~ --help ]]; then
usage && exit 1 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 fi
mode="$1" mode=$1
# Remove single quotes from the arg. arg=$2
arg="${2//\'/}" arg2=$3 # either optional keys or utils config.
if [[ $mode == "monitor" ]]; then if [[ $mode == "monitor" ]]; then
keys="$3" call_jq monitors "select(.id == $arg)" "$arg2"
if [[ -n $keys ]]; then
hyprctl monitors -j | jq -C ".[] | select(.id == $arg) | $keys"
else
hyprctl monitors -j | jq -C ".[] | select(.id == $arg)"
fi
elif [[ $mode == "window" ]]; then elif [[ $mode == "window" ]]; then
keys="$3" call_jq clients "select(.address == \"$arg\")" "$arg2"
if [[ -n $keys ]]; then
hyprctl clients -j | jq -C ".[] | select(.address == \"$arg\") | $keys"
else
hyprctl clients -j | jq -C ".[] | select(.address == \"$arg\")"
fi
elif [[ $mode == "workspace" ]]; then elif [[ $mode == "workspace" ]]; then
keys="$3" call_jq workspaces "select(.id == $arg)" "$arg2"
if [[ -n $keys ]]; then
hyprctl workspaces -j | jq -C ".[] | select(.id == $arg) | $keys"
else
hyprctl workspaces -j | jq -C ".[] | select(.id == $arg)"
fi
elif [[ $mode == "utils" ]]; then elif [[ $mode == "utils" ]]; then
config="${3//\'/}" config="${arg2//\'/}"
if [[ ! -f $config ]]; then if [[ ! -f $config ]]; then
log --error "No utility-launcher config found: $config" log --error "No utility-launcher config found: $config"
exit 1 exit 1