btw i use nix
1#!/usr/bin/env bash
2
3ws_nums=($(@wmmsg@ -t get_workspaces \
4 | jq '[.[] | select(.num != -1) | .num ] | sort | .[]'))
5
6# find first element of ws_nums that has a delta between it and it's predecessor greater than 1
7last=0
8for ws_num in ${ws_nums[@]}; do
9 if [ $(("$ws_num" - "$last")) -gt 1 ]; then
10 break
11 fi
12 last="$ws_num"
13done
14
15echo $(("$last" + 1))
16