
# no network ...
# no other folder
# using pledge to

# we don't install x-cmd in the remote server

# x sshr -p 80:8080 -v aaa:bbb <host:port>
# rsync
# when finished, rsync back ...

# using -it
# using auto

# using rsync
# get a list of files ...
# ssh send ...
# ssh back ...

___x_cmd_ssh_run(){
    local portmap=""
    local cpmap=""

    local sshopt=""

    local shellrun="bash"

    while [ $# -gt 0 ]; do
        case "$1" in
            -p)     case "$2" in
                        *:*:*)      arg:add sshopt -L "$2"      ;;
                        *:*)        arg:add sshopt -L "${2%:*}:localhost:${2#*:}"   ;;
                        *)          arg:add sshopt -L "$2:$2"   ;;
                    esac
                    arg:2:shift  ;;

            -A)     arg:add sshopt -A ;     shift ;;

            -s)     shellrun="sh";          shift ;;
            -c)     shellrun="";            shift ;;

            # --cp)   cpmap="$2";       arg:2:shift ;;
            # --pwd)  ;;  # map current folder into ...
            *)      break ;;
        esac
    done

    local host="$1";    shift

    case "$host" in
        *:*)    host="${host%:*}"
                arg:add -p "${host##*:}"
                ;;
    esac

    [ $# -gt 0 ] || set -- bash

    [ ! -t 1 ] ||  arg:add sshopt -t

    arg:add sshopt -q

    if [ -z "$shellrun" ]; then
        ssh:debug ___x_cmd_cmds ssh "$sshopt" "$host" -- "\"\$@\""
        eval ___x_cmd_cmds ssh "$sshopt" "$host" -- "\"\$@\""
    else
        local final="$shellrun"
        if [ -t 1 ]; then
            arg:add final -i
            case "$shellrun" in
                bash|zsh)       arg:add final -t
            esac
        fi
        arg:add final -c

        local x_
        local abc=' . ~/.x-cmd.root/X; '
        while [ $# -gt 0 ]; do
            ___x_cmd_ssh_run___shq1_ "$1"
            abc="${abc} $x_"
            shift
        done

        ___x_cmd_ssh_run___shq1_ "$abc"
        # ___x_cmd_shq1_ "$x_"
        abc="$x_"

        ssh:debug ___x_cmd_cmds ssh "$sshopt" "$host" -- "$final" "$abc"
        eval ___x_cmd_cmds ssh "$sshopt" "$host" -- "$final" "\"\$abc\""
    fi

}

___x_cmd_ssh_run___shq1_(){
    case "$1" in
        *" "*)  ___x_cmd_shq1_ "$1" ;;
        *)      x_="$1" ;;
    esac

}

