Skip to content

Instantly share code, notes, and snippets.

@ineentho
Last active March 26, 2020 13:42
Show Gist options
  • Save ineentho/60008b6f9603e533c612c1999fa46406 to your computer and use it in GitHub Desktop.
Save ineentho/60008b6f9603e533c612c1999fa46406 to your computer and use it in GitHub Desktop.
Cycle the current workspace between all available outputs in sway
#!/bin/sh
# dependencies:
# - jq (pacman -S jq, apt install jq, etc)
outputs_json=$(swaymsg -t get_outputs)
num_outputs=$(echo "$outputs_json" | jq 'length')
focused_output_index=$(echo "$outputs_json" | jq '[.[].focused] | index(true)')
next_output_index=$(("$focused_output_index" + 1))
max_output_index=$(("$num_outputs" - 1))
if [ "$next_output_index" -gt "$max_output_index" ]; then
next_output_index=0
fi
next_output_name=$(echo "$outputs_json" | jq -r ".[$next_output_index].name")
swaymsg move workspace to "$next_output_name"

Cycle the current workspace between all available outputs

Make sway-cycle-workspace executeable and place it in your PATH.

Put this to bind it to a hotkey in your sway config

bindsym $mod+q exec "sway-cycle-workspace"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment