# shellcheck shell=dash

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

if ___x_cmd_is_suitable_advise_env; then
    xrc:mod:lib ohmyposh    advise
fi

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

    local op="$1";  shift
    case "$op" in
        --help|-h)      ___x_cmd help -m ohmyposh           ;;
        ls|fz|update|use|unuse|try|untry|which|current|feature)
                        ___x_cmd_ohmyposh_"$op" "$@"        ;;
        --rc-load)      ___x_cmd_ohmyposh_rc_load "$@"      ;;
        --fzfinfo)      ___x_cmd_ohmyposh_fz_info "$@"      ;;
        --fzdata)       ___x_cmd_ohmyposh_fz_data "$@"      ;;
        --advise-ls)    ___x_cmd_ohmyposh_advise_ls         ;;
        --get_valid_name_)
                        ___x_cmd_ohmyposh___get_valid_name_ "$@" ;;
        --shellconfig)  ___x_cmd_ohmyposh___shellconfig "$@" ;;

        # original-comand
        --|--run)       ___x_cmd_ohmyposh_run "$@"          ;;
        cache|completion|config|\
        debug|disable|enable|font|get|help|\
        init|notice|print|prompt|toggle|upgrade|version|--version)
                        ___x_cmd_ohmyposh_run "$op" "$@"    ;;

        *)              N=ohmyposh M="Unuse subcmd -> $op" log:ret:64
                        ;;
    esac
}

___x_cmd_ohmyposh_rc_load(){
    local name="$1"

    ___x_cmd_ohmyposh_load___applyfile0
    ___x_cmd_ohmyposh_load___main || return $?
    ___x_cmd_ohmyposh_load___applyfile "$name"
}

___x_cmd_ohmyposh_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=ohmyposh M="Not found current prompt theme vendor" log:ret:1
        vendor="$x_"

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

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