#!/usr/bin/env bash

function edit_the_conf() {
    local cfgfile="$XDG_CONFIG_HOME"
    if [ -z "$cfgfile" ]; then
        cfgfile="$HOME/.config"
    fi
    cfgfile="$cfgfile/sspt.conf"

    local edit_conf=
    read -e -p "Edit the sspt.conf file? (Y/n) " $edit_conf
    if [ "$edit_conf" != "n" ] && [ "$edit_conf" != "N" ]; then
        command -v "$EDITOR" >/dev/null 2>&1 && "$EDITOR" "$cfgfile" && return
        command -v "nano" >/dev/null 2>&1 && "nano" "$cfgfile" && return
        command -v "nvim" >/dev/null 2>&1 && "nvim" "$cfgfile" && return
        command -v "vim" >/dev/null 2>&1 && "vim" "$cfgfile" && return
        command -v "vi" >/dev/null 2>&1 && "vi" "$cfgfile" && return
    fi
}

local/bin/sspt --mk-default-config
edit_the_conf
local/bin/sspt pull "https://gitlab.com/PoroCYon/sspt"
local/bin/sspt install "sspt"

