#!/bin/bash
# Toggle between dark and light themes for wezterm and nvim
# Source of truth: ~/.config/theme-state

STATE_FILE="$HOME/.config/theme-state"

# Read current state
current="dark"
if [ -f "$STATE_FILE" ]; then
  current=$(cat "$STATE_FILE" | tr -d '[:space:]')
fi

# Toggle
if [ "$current" = "light" ]; then
  next="dark"
else
  next="light"
fi

# Write new state
# - wezterm watches this file via add_to_config_reload_watch_list and auto-reloads
# - nvim watches this file via vim.uv.fs_event and auto-switches colorscheme
echo "$next" > "$STATE_FILE"
