#!/bin/bash

theme=$(grep -o -P '(?<=local theme = ").*(?=")' /home/nick/.config/awesome/theme/init.lua)

case $theme in
    "nordic_firewatch")
        new_theme="nordic_moon"
        ;;
    "nordic_moon")
        new_theme="nordic_legion"
        ;;
    "nordic_legion")
        new_theme="nordic_firewatch"
        ;;
    *)
esac

# Replace the theme in the init.lua file
sed -i "s/local theme = .*$/local theme = \"$new_theme\"/" /home/nick/.config/awesome/theme/init.lua

# Configure glava
case $new_theme in
    "nordic_firewatch")
        sed -i 's/#request mod .*/#request mod bars/g' /home/nick/.config/glava/rc.glsl
        sed -i 's/#request setgeometry .*/#request setgeometry 0 0 2560 750/g' /home/nick/.config/glava/rc.glsl
        ;;
    "nordic_moon")
        sed -i 's/#request mod .*/#request mod radial/g' /home/nick/.config/glava/rc.glsl
        sed -i 's/#request setgeometry .*/#request setgeometry 0 0 2560 1600/g' /home/nick/.config/glava/rc.glsl
        ;;
    "nordic_legion")
        sed -i 's/#request mod .*/#request mod bars/g' /home/nick/.config/glava/rc.glsl
        sed -i 's/#request setgeometry .*/#request setgeometry 0 0 2560 1600/g' /home/nick/.config/glava/rc.glsl
        ;;
    *)
esac

# Restart glava if it's running
if pgrep glava > /dev/null; then
    killall glava
    glava --desktop &>/dev/null & disown
fi

# Restart awesome
echo 'awesome.restart()' | awesome-client

# Configure conky
case $new_theme in
    "nordic_firewatch")
        pkill conky
        ;;
    "nordic_moon")
        pkill conky
        ;;
    "nordic_legion")
        ;;
    *)
esac
