#!/bin/sh
# changes the color of i3-gaps and the terminal
# needs: $HOME/.scripts/color/i3
# needs: $HOME/.scripts/color/shell
# needs: $HOME/.scripts/color/rofi

# usage: colorchanger <base16_color>
# uses base16_tomorrow-night as default color when run without argument


change_rofi() {
    rb_path=$HOME/.scripts/colors/rofi
    rasi="$rb_path/$base16_color.rasi"
    if [ -f $rasi ]; then
        rm -f "$rb_path/default.rasi"
        ln -s $rasi "$rb_path/default.rasi"
    fi

}


change_xres () {
    bi3_dir=$HOME/.scripts/colors/xres
    xr="$bi3_dir/$base16_color.Xresources"
    if [ -f $xr ]; then
        xrdb -override "$xr"
        i3-msg reload -q
    fi
}


main (){
    change_xres
    change_rofi
    i3-msg reload -q
}

if [ "$1" = "--list" ]; then
    ls -l $HOME/.scripts/colors/xres | awk '{print $9}' | sed 's/\.sh//'
    exit 1
fi

if [ "$#" != "1" ]; then
    echo "[*] Settings default color."
    base16_color="orangina"
else
    echo "[*] Settings colorscheme to $1."
    base16_color=$1
fi

main
