# shellcheck shell=dash

___x_cmd log init starship
xrc:mod:lib     starship        unit    common  ls  load    feature

___x_cmd_starship___main(){
    [ "$#" -gt 0 ]  ||   set -- fz

    local op="$1";  shift
    case "$op" in
        --help|-h)      ___x_cmd help -m starship               ;;
        ls|fz|update|use|unuse|try|untry|load|which|current|feature)
                        ___x_cmd_starship_"$op"         "$@"    ;;
        --rc-load)      ___x_cmd_starship_rc_load       "$@"    ;;
        --fzfinfo)      ___x_cmd_starship_fz_info       "$@"    ;;
        --fzdata)       ___x_cmd_starship_fz_data       "$@"    ;;
        --get_valid_name_)
                        ___x_cmd_starship___get_valid_name_ "$@" ;;
        --shellconfig)  ___x_cmd_starship___shellconfig "$@"    ;;

        --advise-ls)
                        printf "%s\n" bracketed-segments gruvbox-rainbow jetpack nerd-font-symbols no-empty-icons no-nerd-font no-runtime-versions pastel-powerline plain-text-symbols pure-preset tokyo-night
                        ;;

        # original-comand
        --|--run)       ___x_cmd_starship_run           "$@"    ;;
        bug-report|completions|\
        config|explain|init|module|\
        preset|print-config|prompt|session|timings|toggle|help|-V|--version)
                        ___x_cmd_starship_run "$op"     "$@"    ;;
        *)              N=starship M="Unknown subcmd -> $op" log:ret:64
                        ;;
    esac
}

___x_cmd_starship_rc_load(){
    local name="$1"

    ___x_cmd_starship_load___applyfile0
    ___x_cmd_starship_load___main || return $?
    ___x_cmd_starship_load___applyfile "$name" || return $?
}

___x_cmd_starship_current(){
    local x_=; local vendor=; local name=;

    if [ -n "$___X_CMD_REAL_CALLER_SHELL" ] && [ "$___X_CMD_REAL_CALLER_SHELL" != posix ]; then
        ___x_cmd_theme_boot configfile_get_ "$___X_CMD_REAL_CALLER_SHELL" default || return 1
    else
        x_=; ___x_cmd_theme_boot current_vendor_get_ || N=starship M="Not found current prompt theme vendor" log:ret:1
        vendor="$x_"

        x_=; ___x_cmd_theme_boot current_name_get_ || N=starship M="Not found current prompt theme name" log:ret:1
        name="$x_"
    fi

    ___x_cmd_theme_boot current_style_ "$vendor" "$name"
    if [ "$vendor" != starship ]; then
        starship:info "The prompt theme currently in use has been set by [vendor=$vendor], not by [vendor=starship]."
    fi
    printf "%s\n" "vendor: $vendor" "name: $name"
}
