From a7e6bc893cb948e81309278bed9b58e0d36e9b0b Mon Sep 17 00:00:00 2001 From: Michael Housh Date: Sun, 5 Oct 2025 21:17:04 -0400 Subject: [PATCH] feat: Adds monitor-picker, utility script for generating fzf preview data for pickers. --- env/.local/scripts/hypr/logging | 2 +- env/.local/scripts/hypr/monitor-picker | 101 +++++++++++++++++++++++ env/.local/scripts/hypr/preview-stats | 56 +++++++++++++ env/.local/scripts/hypr/window-picker | 8 +- env/.local/scripts/hypr/workspace-picker | 8 +- gen | 2 +- 6 files changed, 165 insertions(+), 12 deletions(-) create mode 100755 env/.local/scripts/hypr/monitor-picker create mode 100755 env/.local/scripts/hypr/preview-stats diff --git a/env/.local/scripts/hypr/logging b/env/.local/scripts/hypr/logging index e90ce3a..d16f0fa 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 "$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/monitor-picker b/env/.local/scripts/hypr/monitor-picker new file mode 100755 index 0000000..9d4cbc1 --- /dev/null +++ b/env/.local/scripts/hypr/monitor-picker @@ -0,0 +1,101 @@ +#!/usr/bin/env bash + +SCRIPTS=${SCRIPTS:-$HOME/.local/scripts} +THIS_FILE=${BASH_SOURCE[0]} +THIS=$(basename $THIS_FILE) + +usage() { + cat < + +MODES: + + monitor: Get monitor data, arg is the monitor id. + window: Get window data, arg is the window address. + workspace: Get workspace data, arg is the workspace id. + +EOF +} + +# Logging utility function, use in place of echo. +log() { + logging log --source "$THIS_FILE" "$@" +} + +################################################################################ +# MAIN +################################################################################ + +# Setup logging file and label. +source "$SCRIPTS/hypr/logging" +setup-logging "$THIS" + +if [[ ! "${#@}" == "2" ]]; then + log --error "Unexpected argument count: ${#@}, expected: 2" + usage && exit 1 +fi + +mode="$1" +# Remove single quotes from the arg. +arg="${2//\'/}" + +if [[ $mode == "monitor" ]]; then + hyprctl monitors -j | jq -C ".[] | select(.id == $arg)" +elif [[ $mode == "window" ]]; then + hyprctl clients -j | jq -C ".[] | select(.address == \"$arg\")" +elif [[ $mode == "workspace" ]]; then + hyprctl workspaces -j | jq -C ".[] | select(.id == $arg)" +else + log --error "Unexpected mode: $mode" + usage && exit 1 +fi diff --git a/env/.local/scripts/hypr/window-picker b/env/.local/scripts/hypr/window-picker index ae7b9aa..9f54b2a 100755 --- a/env/.local/scripts/hypr/window-picker +++ b/env/.local/scripts/hypr/window-picker @@ -48,13 +48,11 @@ EOF generate_rows() { readarray -t addresses <<<"$(echo "$window_data" | jq -r '.[] | .address')" - readarray -t classes <<<$(echo "$window_data" | jq -r '.[] | .class') readarray -t titles <<<$(echo "$window_data" | jq -r '.[] | .title') - readarray -t workspaces <<<$(echo "$window_data" | jq -r '.[] | .workspace.name') # Zip into rows. for i in "${!addresses[@]}"; do - rows+=("${addresses[i]}|${workspaces[i]}|${classes[i]}|${titles[i]}") + rows+=("${addresses[i]}|${titles[i]}") done } @@ -75,8 +73,8 @@ generate_rows sel=$( printf '%s\n' "${rows[@]}" | fzf --style=full "${fzf_opts[@]}" \ - --preview-label='[ Window Stats ]' --delimiter='|' --with-nth=4 \ - --preview='echo -e "Title: {4}\nClass: {3}\nWorkspace: {2}\nAddress: {1}"' + --preview-label='[ Window Stats ]' --delimiter='|' --with-nth=2 \ + --preview="$SCRIPTS/hypr/preview-stats window {1}" ) [[ -z $sel ]] && exit 1 diff --git a/env/.local/scripts/hypr/workspace-picker b/env/.local/scripts/hypr/workspace-picker index 67864c1..2b2673d 100755 --- a/env/.local/scripts/hypr/workspace-picker +++ b/env/.local/scripts/hypr/workspace-picker @@ -69,11 +69,9 @@ EOF generate_rows() { readarray -t names <<<"$(echo "$workspaces" | jq -r '.[] | .name')" readarray -t ids <<<"$(echo "$workspaces" | jq -r '.[] | .id')" - readarray -t monitors <<<"$(echo "$workspaces" | jq -r '.[] | .monitor')" - readarray -t windows <<<"$(echo "$workspaces" | jq -r '.[] | .windows')" for i in "${!names[@]}"; do - rows+=("${ids[i]}|${monitors[i]}|${windows[i]}|${names[i]}") + rows+=("${ids[i]}|${names[i]}") done } @@ -93,9 +91,9 @@ fi sel=$( printf "%s\n" "${rows[@]}" | - fzf --style=full "${fzf_opts[@]}" --delimiter='|' --with-nth=4 \ + fzf --style=full "${fzf_opts[@]}" --delimiter='|' --with-nth=2 \ --preview-label='[ Workspace Stats ]' \ - --preview='printf "Name: {4}\nID: {1}\nWindows: {3}\nMonitor: {2}"' + --preview="$SCRIPTS/hypr/preview-stats workspace {1}" ) [[ -z $sel ]] && exit 1 diff --git a/gen b/gen index 1527165..5ef1ce3 100755 --- a/gen +++ b/gen @@ -89,7 +89,7 @@ log() { # Setup logging file and label. source "$SCRIPTS/hypr/logging" -setup-logging "/tmp/THIS.log" "$THIS" +setup-logging "$THIS" log "Starting $THIS..."