.dotfiles/configs/wofi/sway-select-window.sh
2021-11-28 16:27:03 +01:00

26 lines
827 B
Bash
Executable File

#!/usr/bin/env bash
swaymsg -t get_tree | jq -r '
# descend to workspace or scratchpad
.nodes[].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| {
read -r id name
swaymsg "[con_id=$id]" focus
}