From 7aec9d16104deb1e93ff6417a7940cc4d58b9d5b Mon Sep 17 00:00:00 2001 From: Michael Housh Date: Mon, 6 Oct 2025 19:56:14 -0400 Subject: [PATCH] feat: Adds ability to pipe addresses into close-windows script. --- env/.local/scripts/hypr/close-windows | 21 ++++++++++++++------- env/.local/scripts/hypr/logging | 4 ++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/env/.local/scripts/hypr/close-windows b/env/.local/scripts/hypr/close-windows index 060ca80..d131e41 100755 --- a/env/.local/scripts/hypr/close-windows +++ b/env/.local/scripts/hypr/close-windows @@ -1,5 +1,9 @@ #!/usr/bin/env bash +set -e +set -o nounset +set -o pipefail + THIS_FILE=${BASH_SOURCE[0]} # Allows script name to be set when called from a parent script or defaults to filename. THIS=${THIS:-$(basename "$THIS_FILE")} @@ -43,8 +47,8 @@ all_flag="0" class_flag="0" dry_run_flag="0" special_flag="0" -args=() -addresses=() +args="" +addresses="" SCRIPTS="${SCRIPTS:-$HOME/.local/scripts}" while [[ $# -gt 0 ]]; do @@ -61,7 +65,7 @@ while [[ $# -gt 0 ]]; do elif [[ $1 =~ ^-s ]] || [[ $1 =~ ^--special ]]; then special_flag="1" else - args+=($1) + args+=("$1") fi shift done @@ -122,15 +126,18 @@ elif [[ $special_flag == "1" ]]; then # Set addresses to all windows in the passed in special workspaces. get_special_addresses -else +elif [[ -n $args ]]; then # If no modes selected, then assume there were addresses passed in # as args. - addresses=("$args") + addresses=$args fi +# If no addresses at this point, then read from stdin, which allows addresses +# to be piped in. if [[ ${#addresses} == 0 ]]; then - log --warning "No windows found." - exit 0 + log "No window addresses supplied, reading from stdin..." + read -r addresses + log "Addresses: ${addresses[@]}" fi for address in ${addresses[@]}; do diff --git a/env/.local/scripts/hypr/logging b/env/.local/scripts/hypr/logging index d278608..f9b2b5e 100755 --- a/env/.local/scripts/hypr/logging +++ b/env/.local/scripts/hypr/logging @@ -30,7 +30,7 @@ LOG_FILE=(${LOG_FILE:-}) LOG_INVOCATION_ID=${LOG_INVOCATION_ID:-} -LOG_LABEL=(${LOG_LABEL:-}) +LOG_LABEL=${LOG_LABEL:-()} # Run in dry run mode, which just prints to the console and does # not log to the files. LOG_ENABLE_DRY_RUN=${LOG_ENABLE_DRY_RUN:-"0"} @@ -144,7 +144,7 @@ setup-logging() { LOG_FILE+=("$file") LOG_INVOCATION_ID=${LOG_INVOCATION_ID:-$RANDOM} - if [[ -n "$LOG_LABEL" ]]; then + if [[ -n $LOG_LABEL ]]; then LOG_LABEL+=("${LOG_LABEL[@]}=>$label") else LOG_LABEL+=("$label")