#!/usr/bin/env bash

remove-dotenv() {
    if [[ -z "$1" ]]; then
        echo "\$1/env is empty."
        return 1
    fi
    TASK_DOTENV_DIR=${TASK_DOTENV_DIR:="$HOME/.config/taskfile.build"}

    local env_name="$1"
    local env_filepath=""

    if [[ -f "$TASK_DOTENV_DIR/$env_name.env" ]]; then
        env_filepath="$TASK_DOTENV_DIR/$env_name.env"
    elif [[ -f "$PWD/$env_name.env" ]]; then
        env_filepath="$PWD/$env_name.env"
    elif [[ -f "$TASK_DOTENV_DIR/.env.$env_name" ]]; then
        env_filepath="$TASK_DOTENV_DIR/.env.$env_name"
    fi

    if [[ -z "$env_filepath" ]]; then
        echo "Env '$env_name' not found."
        return 1
    fi

    rm "$env_filepath"
    echo "Removed $env_filepath."
}
rdo() {
    remove-dotenv "$@"
}
