Skip to content

Instantly share code, notes, and snippets.

@CIAvash
Last active June 2, 2021 20:48
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 CIAvash/ac323bdf775210a272a28707c6b123ba to your computer and use it in GitHub Desktop.
Save CIAvash/ac323bdf775210a272a28707c6b123ba to your computer and use it in GitHub Desktop.
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