#!/usr/bin/env bash

SETTINGS=$HOME/.config/rofi/gtk-theme.ini

#Gets the current gtk using gsettings and removes the quotes
CURRENT_GTK_THEME=$(gsettings get org.gnome.desktop.interface gtk-theme)
CURRENT_GTK_THEME="${CURRENT_GTK_THEME#?}"
CURRENT_GTK_THEME="${CURRENT_GTK_THEME%?}"

#Gets the gtk theme that is in the settings.ini file
SETTINGS_GTK_THEME=$(grep "GTK_THEME" "${SETTINGS}" | cut -b 11-)

#create new colors.rasi from template
if [ "${SETTINGS_GTK_THEME}" != "${CURRENT_GTK_THEME}" ]; then
  sed -i "s:GTK_THEME=${SETTINGS_GTK_THEME}:GTK_THEME=${CURRENT_GTK_THEME}:g" "${SETTINGS}"

  python3 $HOME/.config/rofi/file_gtk_style.py "${HOME}"/.config/rofi/_template/colors.rasi > "${HOME}"/.config/rofi/colors.rasi
fi

case $1 in 
  window)
    showmode="window" 
    ;;
  files)
    showmode="filebrowser" 
    ;;
  run)
    showmode="run" 
    ;;
  *) 
    showmode="drun" 
    ;; 
esac

## Run
rofi \
    -show $showmode \
    -click-to-exit \
    -theme ~/.config/rofi/launcher/launcher.rasi