# shellcheck shell=dash disable=SC2124
___X_CMD_TCSH_SETUP_RCCODE='test ! -e "$HOME/.x-cmd.root/local/data/tcsh/rc.tcsh" || source "$HOME/.x-cmd.root/local/data/tcsh/rc.tcsh" # boot up x-cmd.'

___x_cmd_tcsh___setup(){
    local tcsh_bin_fp="$HOME/.x-cmd.root/bin/rc.x.tcsh"
    ___x_cmd_tcsh___prepare "$tcsh_bin_fp"
    ___x_cmd cp -f "$___X_CMD_ROOT_MOD/tcsh/lib/rc/rc.x.tcsh" "$tcsh_bin_fp"


    local rc_tcsh_fp="$HOME/.x-cmd.root/local/data/tcsh/rc.tcsh"
    ___x_cmd_tcsh___prepare "$rc_tcsh_fp"
    ___x_cmd cp -f "$___X_CMD_ROOT_MOD/tcsh/lib/rc/rc.tcsh" "$rc_tcsh_fp"

    ___x_cmd boot initrcfile1  "$___X_CMD_TCSH_SETUP_RCCODE"     "$HOME/.tcshrc" || return $?
    ___x_cmd shortcut compile tcsh || return $?

    ___x_cmd ensurefp "$HOME/.x-cmd.root/local/cache/advise/bootcode/v0.0.0.tcsh"
    ___x_cmd advise complete tcsh code > "$HOME/.x-cmd.root/local/cache/advise/bootcode/v0.0.0.tcsh"
}

___x_cmd_tcsh___prepare(){
    ___x_cmd ensurefp "$1"
    [ ! -f "$1" ] || ___x_cmd rm "$1"
}

___x_cmd_tcsh___setup_is_required(){
    ! {
        ___x_cmd boot ensurerccodewithoutextra    \
                                    "$___X_CMD_TCSH_SETUP_RCCODE"                   "$HOME/.tcshrc"                                && \
            ___x_cmd_cmds cmp       "$___X_CMD_ROOT_MOD/tcsh/lib/rc/rc.tcsh"        "$HOME/.x-cmd.root/local/data/tcsh/rc.tcsh"    && \
            ___x_cmd_cmds cmp       "$___X_CMD_ROOT_MOD/tcsh/lib/rc/rc.x.tcsh"      "$HOME/.x-cmd.root/bin/rc.x.tcsh"
    } 1>/dev/null 2>/dev/null
}
