Skip to content

Instantly share code, notes, and snippets.

@chr5tphr
Created June 28, 2021 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chr5tphr/e49948b0e5ab6a4ffd143fc3e548a4d9 to your computer and use it in GitHub Desktop.
Save chr5tphr/e49948b0e5ab6a4ffd143fc3e548a4d9 to your computer and use it in GitHub Desktop.
Find a window in sway with wofi and use use it as a criterion in a swaymsg.
#!/usr/bin/env bash
JQWINS='
[recurse(.nodes[])] |
[
.[] |
select(has("app_id")) |
(.id | tostring) + "\t" + .name + (" [" + if .app_id then .app_id else .shell end + "]")
] |
join("\n")
'
mapfile -t windows < <(swaymsg -t get_tree | jq -r "${JQWINS}")
identifiers=("${windows[@]%%$'\t'*}")
names=("${windows[@]##*$'\t'}")
index="$(wofi --dmenu -i -D dmenu-print_line_num=true < <(printf '%s\n' "${names[@]}") 2>/dev/null)"
[ -z "$index" ] || swaymsg "[con_id=${identifiers[${index}]}]" "${@:-focus}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment