#!/bin/sh
# Cycle Hyprland workspaces within the fixed 1..10 desktop set.

set -eu

direction="${1:-next}"
current="$(hyprctl activeworkspace -j | jq -r '.id')"

case "$current" in
  ''|*[!0-9-]*) current=1 ;;
esac

case "$direction" in
  next)
    if [ "$current" -ge 10 ] || [ "$current" -lt 1 ]; then
      target=1
    else
      target=$((current + 1))
    fi
    ;;
  prev)
    if [ "$current" -le 1 ] || [ "$current" -gt 10 ]; then
      target=10
    else
      target=$((current - 1))
    fi
    ;;
  *)
    printf 'Usage: %s {next|prev}\n' "$0" >&2
    exit 1
    ;;
esac

exec hyprctl dispatch workspace "$target"
