# shellcheck shell=dash

___x_cmd_starship_load___main(){
    local shellname="${1:-$___X_CMD_SHELL}"
    case "$shellname" in
        zsh)    ;;
        bash)
            case "$PROMPT_COMMAND" in
                __vsc_prompt_cmd_original)
                    starship:info --issue "https://github.com/starship/starship/issues/5816" "To prevent the terminal from crashing, unset the PROMPT_COMMAND variable "
                    unset PROMPT_COMMAND
                    ;;
            esac
            ;;
        *)  starship:warn "Todo"; return 1 ;;
    esac
    eval "$( ___x_cmd_starship_run init "$shellname" || printf "%s\n" "false" )" || return $?

    if [ -n "$ZSH_VERSION" ]; then
        local x_=; ___x_cmd_starship_feature_get_ zshplugin || return $?
        starship:debug "The starship [feature=zshplugin] is '$x_'"
        [ "$x_" = never ] || ___x_cmd zshplugin load
    fi
}

___x_cmd_starship_load___applyfile(){
    local name="$1"
    local x_=; ___x_cmd_starship_which_ "$name" || return $?
    export STARSHIP_CONFIG="$x_"
}

___x_cmd_starship_load___applyfile0(){
    ___x_cmd_theme_boot current_vendor_unset
    unset STARSHIP_CONFIG
}

___x_cmd_starship___shellconfig(){
    local shellname="$1"
    local name="$2"
    local x_=; ___x_cmd_starship_which_ "$name" || return $?

    STARSHIP_CONFIG="$x_" ___x_cmd_starship_run init "$shellname" || return $?

    case "$shellname" in
        powershell)
            ___x_cmd pwsh path linux_to_win_ "$x_" || return $?
            printf "\n%s\n" "\$env:STARSHIP_CONFIG=\"$x_\"" ;;
        fish)
            printf "\n%s\n" "set -x STARSHIP_CONFIG \"$x_\"" ;;
        elvish)
            printf "\n%s\n" "set-env STARSHIP_CONFIG \"$x_\"" ;;
        xonsh)
            printf "\n%s\n" "\$STARSHIP_CONFIG = \"$x_\"" ;;
        nu)
            printf "\n%s\n" "\$env.STARSHIP_CONFIG = \"$x_\"" ;;
        tcsh)
            printf "\n%s\n" "setenv STARSHIP_CONFIG \"$x_\"" ;;
        *) ;;
    esac
}
