.dotfiles/configs/wofi/sway-select-window.sh

26 lines
852 B
Bash
Raw Normal View History

2021-11-28 16:19:50 +01:00
#!/usr/bin/env bash
swaymsg -t get_tree | jq -r '
# descend to workspace or scratchpad
.nodes[].nodes[]
# save workspace name as .w
| {"w": .name} + (
if .nodes then # workspace
[recurse(.nodes[])]
else # scratchpad
[]
end
+ .floating_nodes
| .[]
# select nodes with no children (windows)
| select(.nodes==[])
)
| ((.id | tostring) + "\t "
# remove markup and index from workspace name, replace scratch with "[S]"
+ (.w | gsub("^[^:]*:|<[^>]*>"; "") | sub("__i3_scratch"; "[S]"))
+ "\t " + .name)
' | wofi --show dmenu -Ddynamic-lines=true --prompt=0 | {
read -r id name
swaymsg "[con_id=$id]" focus
}