feat: Adds ability for window picker to only show windows for a given workspace, in prep for adding workspace action picker.

This commit is contained in:
2025-10-09 10:25:30 -04:00
parent 933ce337a1
commit 6332eafea5

View File

@@ -5,7 +5,15 @@ set -o nounset
set -o pipefail set -o pipefail
SCRIPTS=${SCRIPTS:-$HOME/.local/scripts} SCRIPTS=${SCRIPTS:-$HOME/.local/scripts}
THIS=${THIS:-$(basename ${BASH_SOURCE[0]})} THIS_FILE=${BASH_SOURCE[0]}
LOG_LABEL=$(basename $THIS_FILE)
THIS=${THIS:-$LOG_LABEL}
LOG_FILE=${LOG_FILE:-/tmp/$LOG_LABEL.log}
uses_supplied_footer="0"
fzf_opts=()
rows=()
workspace_id=""
usage() { usage() {
cat <<EOF cat <<EOF
@@ -17,6 +25,7 @@ USAGE:
$ $THIS <flags> [FZF_OPTIONS] $ $THIS <flags> [FZF_OPTIONS]
FLAGS: FLAGS:
-w | --workspace <id>: Only show windows for the given workspace.
-h | --help: Show this help page. -h | --help: Show this help page.
NOTES: NOTES:
@@ -27,11 +36,10 @@ Any other options or arguments are passed directly to 'fzf'.
EOF EOF
} }
uses_supplied_footer="0" # Logging utility function, use in place of echo.
log() {
fzf_opts=() logging log --source "$THIS_FILE" "$@"
rows=() }
window_data=$(hyprctl clients -j | jq 'sort_by(.workspace.id)')
footer() { footer() {
cat <<'EOF' cat <<'EOF'
@@ -43,13 +51,17 @@ EOF
} }
generate_rows() { generate_rows() {
local addresses=()
readarray -t addresses <<<"$(echo "$window_data" | jq -r '.[] | .address')" if [[ -n $workspace_id ]]; then
readarray -t titles <<<$(echo "$window_data" | jq -r '.[] | .title') addresses=$(hyprctl clients -j | jq -r ".[] | select(.workspace.id == $workspace_id) | .address")
else
addresses=$(hyprctl clients -j | jq -r ".[] | .address")
fi
# Zip into rows. for address in $addresses; do
for i in "${!addresses[@]}"; do title=$(hyprctl clients -j | jq -r ".[] | select(.address == \"$address\") | .title")
rows+=("${addresses[i]}|${titles[i]}") rows+=("$address|$title")
done done
} }
@@ -57,12 +69,19 @@ generate_rows() {
# MAIN # MAIN
################################################################################ ################################################################################
# Setup logging file and label.
source "$SCRIPTS/hypr/logging"
setup-logging "$LOG_FILE" "$LOG_LABEL"
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
if [[ $1 =~ ^--footer ]]; then if [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then
usage && exit 0
elif [[ $1 =~ ^--footer ]]; then
uses_supplied_footer="1" uses_supplied_footer="1"
fzf_opts+=("$1") fzf_opts+=("$1")
elif [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then elif [[ $1 == "-w" ]] || [[ $1 == "--workspace" ]]; then
usage && exit 0 shift
workspace_id=$1
else else
fzf_opts+=("$1") fzf_opts+=("$1")
fi fi