

# ___x_cmd_theme_boot___configfile_set      posix vscode starship xxx
# ___x_cmd_theme_boot___configfile_unset    posix vscode
___x_cmd_theme_boot___configfile_set(){
    local envshell="${1:-posix}"
    local terminal="${2:-default}"
    local vendor="$3";      [ -n "$vendor" ]    || N=theme M="Please provide prompt theme vendor value"     log:ret:64
    local name="$4";        [ -n "$name" ]      || N=theme M="Please provide prompt theme name value"       log:ret:64

    local configdir="$___X_CMD_ROOT_CFG/theme/use/$envshell"

    if [ "$envshell" != "posix" ]; then
        case "$vendor" in
            ohmyposh|starship)
                local suffix="$envshell"
                case "$envshell" in
                    powershell) suffix="ps1" ;;
                    xonsh)      suffix="xsh" ;;
                    elvish)     suffix="elv" ;;
                esac
                local codefile="$configdir/$terminal.$suffix"
                ___x_cmd ensurefp "$codefile"
                ___x_cmd "$vendor" --shellconfig "$envshell" "$name" > "$codefile";;
            *)  N=theme M="The prompt theme [vendor=$vendor] is not supported in the $envshell environment" log:ret:1 ;;
        esac
    fi

    local configfile="$configdir/$terminal"
    ___x_cmd ensurefp "$configfile"
    printf "%s\n" "$vendor" "$name" > "$configfile"
}

___x_cmd_theme_boot___configfile_unset(){
    local envshell="${1:-posix}"
    local terminal="${2:-default}"

    local configdir="$___X_CMD_ROOT_CFG/theme/use/$envshell"
    local configfile="$configdir/$terminal"
    [ -f "$configfile" ] || return 0
    case "$envshell" in
        nu) ___x_cmd_cmds rm -rf "$configfile"
            printf "" > "$configfile.nu"
            ;;
        *)  ___x_cmd_cmds rm -rf "$configdir/$terminal"*
            ;;
    esac

    ! ___x_cmd fsiter --dirempty "$configdir" || ___x_cmd rmrf "$configdir"
}

___x_cmd_theme_boot___configfile_get_(){
    local envshell="${1:-posix}"
    local terminal="${2:-default}"
    local configfile="$___X_CMD_ROOT_CFG/theme/use/$envshell/$terminal"
    vendor=;    name=
    [ -f "$configfile" ] || return
    { read -r vendor && read -r name ; } < "$configfile"
    { [ -n "$vendor" ] && [ -n "$name" ]; } || N=theme M="Fail to fetch vendor in $configfile" log:ret:1
}

___x_cmd_theme_boot___configfile_check(){
    local envshell="${1:-posix}"
    local terminal="${2:-default}"
    local configfile="$___X_CMD_ROOT_CFG/theme/use/$envshell/$terminal"
    [ -f "$configfile" ]
}

# configdir
___x_cmd_theme_boot___configdir_check(){
    local envshell="${1:-posix}"
    local configdir="$___X_CMD_ROOT_CFG/theme/use/$envshell"
    [ -d "$configdir" ]
}

___x_cmd_theme_boot___configdir_unset(){
    local envshell="${1:-posix}"
    local configdir="$___X_CMD_ROOT_CFG/theme/use/$envshell"
    case "$envshell" in
        nu)
            local l=
            ___x_cmd_cmds find "$configdir" -type f | while read -r l; do
                if [ "$l" = "${l%".nu"}" ]; then
                    ___x_cmd rmrf "$l"
                else
                    printf "" > "$l"
                fi
            done
            ;;
        *)
            ___x_cmd rmrf "$configdir"
            ;;
    esac
}
