Skip to content

Instantly share code, notes, and snippets.

@enko
Created July 16, 2023 19:55
Show Gist options
  • Save enko/25fe986f58369834c89b30ffc7abe7ce to your computer and use it in GitHub Desktop.
Save enko/25fe986f58369834c89b30ffc7abe7ce to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -euo pipefail
tree=$(swaymsg -t get_tree)
readarray -t win_ids <<< "$(jq -r '.. | objects | select(has("app_id")) | .id' <<< "$tree")"
readarray -t win_names <<< "$(jq -r '.. | objects | select(has("app_id")) | .name' <<< "$tree")"
readarray -t win_types <<< "$(jq -r '.. | objects | select(has("app_id")) | .app_id // .window_properties.class' <<< "$tree")"
switch () {
local k
read -r k
swaymsg "[con_id=${win_ids[$k]}] focus"
}
for k in $(seq 0 $((${#win_ids[@]} - 1))); do
echo -e "<span weight=\"bold\">${win_types[$k]}</span> - ${win_names[$k]}"
done | rofi -dmenu -markup-rows -i -p window -format i | switch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment