From 78e40a9401736cba69bf2e426a6325f0b80b4f48 Mon Sep 17 00:00:00 2001 From: Michael Housh Date: Mon, 6 Oct 2025 17:01:07 -0400 Subject: [PATCH] feat: Begins moving some scripts into a utils folder and using them as subcommands. --- env/.local/scripts/hypr/close-windows | 3 +- .../scripts/hypr/utils/windows/close-windows | 139 ++++++++++++++++++ env/.local/scripts/hypr/windowctl | 10 +- gen | 5 +- 4 files changed, 152 insertions(+), 5 deletions(-) create mode 100755 env/.local/scripts/hypr/utils/windows/close-windows diff --git a/env/.local/scripts/hypr/close-windows b/env/.local/scripts/hypr/close-windows index add7e29..060ca80 100755 --- a/env/.local/scripts/hypr/close-windows +++ b/env/.local/scripts/hypr/close-windows @@ -1,7 +1,8 @@ #!/usr/bin/env bash THIS_FILE=${BASH_SOURCE[0]} -THIS=$(basename "$THIS_FILE") +# Allows script name to be set when called from a parent script or defaults to filename. +THIS=${THIS:-$(basename "$THIS_FILE")} usage() { cat </dev/null 2>&1 + fi +} + +# Setup logging file and label +source "$SCRIPTS/hypr/logging" +setup-logging "$LOG_LABEL" +export LOG_ENABLE_DRY_RUN="$dry_run_flag" + +if [[ $active_workspace_flag == "1" ]]; then + # Set addresses to active workspace windows. + id=$(hyprctl activeworkspace -j | jq -r '.id') + log "Fetching addresses for active workspace: $id" + addresses+=("$(hyprctl clients -j | jq -r ".[] | select(.workspace.id == $id) | .address")") + +elif [[ $all_flag == "1" ]]; then + # Set addresses to all window addresses. + addresses+=("$(hyprctl clients -j | jq -r ".[] | .address")") + +elif [[ $class_flag == "1" ]]; then + # Set addresses to all windows containing the passed in classes. + for c in ${args[@]}; do + _select_addresses .class $c + done + +elif [[ $special_flag == "1" ]]; then + # Set addresses to all windows in the passed in special workspaces. + get_special_addresses + +else + # If no modes selected, then assume there were addresses passed in + # as args. + addresses=("$args") +fi + +if [[ ${#addresses} == 0 ]]; then + log --warning "No windows found." + exit 0 +fi + +for address in ${addresses[@]}; do + close $address +done diff --git a/env/.local/scripts/hypr/windowctl b/env/.local/scripts/hypr/windowctl index 7e212f5..577ca28 100755 --- a/env/.local/scripts/hypr/windowctl +++ b/env/.local/scripts/hypr/windowctl @@ -1,6 +1,8 @@ #!/usr/bin/env bash + THIS_FILE=${BASH_SOURCE[0]} THIS=$(basename $THIS_FILE) +SCRIPTS=${SCRIPTS:-$HOME/.local/scripts} usage() { cat <