#!/bin/bash

################################################################################
## theming app for instantOS                                                  ##
## Aims to configure as much applications as possible to conform to the theme ##
################################################################################

cd
source /usr/share/paperbash/import.sh

pb git
pb config
pb gtk
pb instantos

if [ -n "$2" ]; then
    APPLYTHEME=$2
else
    if [ -e ~/instantos/themes/config ]; then
        APPLYTHEME=$(cat ~/instantos/themes/config)
    else
        echo "using default theme"
        APPLYTHEME="arc"
    fi
fi

source /usr/share/instantthemes/$APPLYTHEME.sh
ACTION=${1:-apply}

tapply() {
    echo "applying $APPLYTHEME theme"
    instanttheme "$APPLYTHEME"
    themeapply
}

case "$ACTION" in
a)
    tapply
    ;;
f)
    themefetch
    ;;
d)
    if command -v darktheme; then
        darktheme
        exit
    else
        echo "no dark theme available for $APPLYTHEME"
    fi
    ;;
l)
    if command -v lighttheme; then
        lighttheme
        exit
    else
        echo "no light theme available for $APPLYTHEME"
    fi
    ;;
*)
    themefetch
    tapply
    ;;
esac
