#!/bin/zsh CUR_WORKSPACE=$(swaymsg -t get_workspaces | jq -r '. | sort_by(.num) | map(.num) | .[]') previous=0 while IFS= read -r n; do if (( n != previous + 1 )) ; then NEW_WORKSPACE=$(( previous + 1 )) break fi previous=$n done <<< "$CUR_WORKSPACE" swaymsg workspace number $NEW_WORKSPACE