flake-update-20260505
 1#!/usr/bin/env bash
 2# List niri windows for raffi script filter (switch or kill).
 3# Outputs Alfred Script Filter JSON format.
 4# Usage: niri-windows-raffi [query]
 5#
 6# arg format: window id for use with niri msg action focus-window / close-window
 7set -euo pipefail
 8
 9query="${1:-}"
10
11items="[]"
12while IFS=$'\t' read -r wid app_id title ws_id; do
13    [[ -z "$wid" ]] && continue
14    subtitle="${app_id} — workspace ${ws_id}"
15    if [[ -n "$query" ]] && ! echo "$title $app_id" | grep -qi "$query"; then
16        continue
17    fi
18    items=$(jq --arg title "$title" --arg sub "$subtitle" --arg arg "$wid" \
19        '. + [{"title": $title, "subtitle": $sub, "arg": $arg}]' <<< "$items")
20done < <(niri msg -j windows 2>/dev/null | jq -r '
21    .[] | [(.id | tostring), (.app_id // "unknown"), (.title // ""), (.workspace_id // 0 | tostring)] | @tsv
22')
23
24if [[ "$items" == "[]" ]]; then
25    jq -n '{"items": [{"title": "No windows found", "subtitle": "No open niri windows", "arg": ""}]}'
26    exit 0
27fi
28
29jq -n --argjson items "$items" '{"items": $items}'