Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Switch windows in sway with rofi(dmenu)
#!/usr/bin/env bash
windows=$(swaymsg -t get_tree | jq -r '.. | select(.type? and .type=="workspace") | {workspace: .name, node: recurse(.nodes[], .floating_nodes[])} | "[\(.workspace)]:" + if .node.focused then "*" else "" end + " \(.node.id): " + if .node.app_id then "\(.node.app_id)" elif .node.window then "\(.node.window_properties.class)" else empty end + ": \(.node.name)"')
active_window=$(echo "$windows" | grep -nE '^\[[[:alnum:]]+\]:\*' | cut -d : -f 1)
echo "$windows" | rofi -dmenu -a $(($active_window - 1)) -i -p 'Select window: ' | cut -d : -f 2 | xargs -I{} swaymsg '[con_id={}] focus'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment