mirror of
https://github.com/prdlk/dotfiles.git
synced 2026-11-02 11:32:42 +00:00
25 lines
964 B
Bash
25 lines
964 B
Bash
#!/bin/sh
|
|||
|
|
# umbriel-launch PATTERN COMMAND...
|
||
|
|
# Focus the next workspace window whose app id matches PATTERN (a
|
||
|
|
# case-insensitive jq regex), cycling through matches on repeated presses;
|
||
|
|
# with none open, spawn COMMAND. Scratchpad windows are skipped: they have
|
||
|
|
# their own toggles. Umbriel counterpart of niri-launch / omarchy-cycle.
|
||
|
|
set -eu
|
||
|
|
|
||
|
|
[ $# -ge 2 ] || { echo "usage: umbriel-launch PATTERN COMMAND..." >&2; exit 2; }
|
||
|
|
pattern=$1
|
||
|
|
shift
|
||
|
|
|
||
|
|
# Matches in a stable order (window id); the one after the focused match, or
|
||
|
|
# the first when focus is elsewhere.
|
||
|
|
target=$(umbriel windows --json | jq -r --arg p "$pattern" '
|
||
|
|
[.[] | select(.scratchpad == "" and (.app_id | test($p; "i")))] | sort_by(.id)
|
||
|
|
| if length == 0 then empty
|
||
|
|
else (map(.focused) | index(true)) as $i
|
||
|
|
| if $i == null then .[0].id else .[($i + 1) % length].id end
|
||
|
|
end')
|
||
|
|
|
||
|
|
if [ -n "$target" ]; then
|
||
|
|
exec umbriel msg "window-focus:$target"
|
||
|
|
fi
|
||
|
|
exec umbriel msg spawn "$@"
|