#!/bin/bash
set -e

# Cycles to the next available theme (wraps from last back to first).

mapfile -t THEMES < <(nomarchy-theme-list)
TOTAL=${#THEMES[@]}

if (( TOTAL == 0 )); then
  notify-send "No themes available"
  exit 1
fi

CURRENT=$(nomarchy-theme-current)
INDEX=-1
for i in "${!THEMES[@]}"; do
  if [[ "${THEMES[$i]}" == "$CURRENT" ]]; then
    INDEX=$i
    break
  fi
done

NEXT_INDEX=$(((INDEX + 1) % TOTAL))
nomarchy-theme-set "${THEMES[$NEXT_INDEX]}"
