# shellcheck shell=dash

___x_cmd_cd_relm___magic(){
    local p="$1"
    case "$p" in
        :|:/)       shift; ___x_cmd_cd_origin "$___X_CMD_CD_RELM_0" "$@"    ;;
        :/*)        shift; ___x_cmd_cd_origin "$___X_CMD_CD_RELM_0" \
                    && ___x_cmd_cd___main "${p#:/}" "$@"                    ;;

        # :*/*)       ___x_cmd_cd_relm___goto_inner "${p#:}"                  ;;
        # :*)         shift; ___x_cmd_cd_relm___goto_or_set "${p#:}" "$@"     ;;

        :*)         ___x_cmd_cd_relm___magic0 "$@" ;;
        *)          N=cd M="Not found such [subcmd=$p]" log:ret:64 ;;
    esac
}

___x_cmd_cd_relm___magic0(){
    local count="$((count + 1))"
    [ "$count" -lt 3 ] || N=cd M="recursive more than 3" log:ret:1

    case "$1" in
        :*/*)
            local p0="${1%%/*}"
            local p1="${1#*/}"
            local x_=; ___x_cmd_cd_relm___get_ "${p0#:}" || {
                cd:error "RELM NOT found ==> $p0"
                return 1
            }
            shift; ___x_cmd_cd_relm___magic0 "$x_/$p1" "$@"
            ;;
        :*)
            local x_=; ___x_cmd_cd_relm___get_ "${1#:}" || {
                cd:error "RELM NOT found ==> $1"
                return 1
            }
            shift; ___x_cmd_cd_relm___magic0 "$x_" "$@"
            ;;
        *)
            ___x_cmd_cd_origin "$@"
            ;;
    esac
}
