#!/bin/bash

usage () {
    printf "%s" "\
USAGE: 
    install [OPTIONS] [ARGS]

ARGS:
    <WM>
        Window managers, for which you want to install files.

OPTIONS:
    -h, --help
        Show this message.

    --prefix
        Used for specifying installation directory.

    --clean
        When specified, this script cleans directory specified in '--prefix' 
        option.
"

exit 1
}


init_config_file () {
    mkdir --parents "$XDG_CONFIG_HOME/ixwindow"
    cp "examples/ixwindow.toml" "$XDG_CONFIG_HOME/ixwindow/ixwindow.toml"
}

install () {
    if [ "$CLEAN" -eq 1 ]; then
        rm -r "$PREFIX"
    fi
            
    # Remove ixwindow file from previous installation
    rm -r "$PREFIX/ixwindow" 2> /dev/null

    cargo build --release
   
    mkdir -p "$PREFIX"
    cp -r target/release/ixwindow "$PREFIX" 
}


CLEAN=0
PREFIX="$HOME/.config/polybar/scripts/ixwindow"

while [ $# -gt 0 ];
do
    case "$1" in 
        "--help" | "-h")
            usage 
            ;;
        "--clean")
            CLEAN=1
            shift
            ;;
        "--prefix")
            PREFIX="$2"
            shift 2
            ;;
        *)
            ;;
    esac
done


install

init_config_file 

