vitorpy's Dotfiles
at main 27 lines 785 B view raw
1#!/usr/bin/env bash 2# Sway: Move window to next free workspace on current monitor 3 4# Get current output 5current_output=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused==true) | .name') 6 7# Get all workspaces on current output 8workspaces=$(swaymsg -t get_workspaces | jq -r --arg out "$current_output" \ 9 '.[] | select(.output==$out) | .num') 10 11# Find first empty workspace or create new one 12empty_ws=0 13for i in {1..100}; do 14 if ! echo "$workspaces" | grep -q "^$i$"; then 15 empty_ws=$i 16 break 17 fi 18done 19 20# If no gap found, use next number after highest 21if [ "$empty_ws" -eq 0 ]; then 22 empty_ws=$(( $(echo "$workspaces" | sort -n | tail -n1) + 1 )) 23fi 24 25# Move window and follow it 26swaymsg move container to workspace number "$empty_ws" 27swaymsg workspace number "$empty_ws"