Skip to content

Instantly share code, notes, and snippets.

@vilhalmer
Created December 25, 2018 04:43
Show Gist options
  • Save vilhalmer/d192d081ec81ff9ae61c4fed5e40b052 to your computer and use it in GitHub Desktop.
Save vilhalmer/d192d081ec81ff9ae61c4fed5e40b052 to your computer and use it in GitHub Desktop.
Select sway containers by index
#!/usr/bin/env bash
# Bless jq, it even does the math for us
swaymsg "[con_id=$(swaymsg -t get_tree | jq "recurse(.nodes[]; .nodes) | .nodes | select(any(.focused)) | .[$1-1].id")]" focus
@vilhalmer
Copy link
Author

vilhalmer commented Dec 25, 2018

bindsym $mod+1 exec sway-focus-container-index 1, etc and it's really handy for hopping around tabbed containers. As a bonus, $mod+0 will hop to the rightmost container since it causes jq to index into the array at -1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment