#!/bin/bash # if [ "${cmd}" == "emacs" ]; then sudo -u prologmud_server -- google-chrome "http://localhost:4125" if [ ! -z "$*" ] && [ ! -f /.dockerenv ]; then docker exec -it logicmoo bash -c "cd $PWD; ${BASH_SOURCE[0]} $*" return 0 2>/dev/null ; exit 0 fi ROOT_DIRECTORY="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" set -o pipefail export SCREEN_CMD="sudo -u prologmud_server -- screen" export DISPLAY LMENV=1 LMENV_ARG= NOX=0 function show_lm_help { . /opt/logicmoo_workspace/logicmoo_env.sh -v #bash -c "cd $ROOT_DIRECTORY ; ls --color" export TAB=`printf '\033[25\`' ` echo -e "\n Executes one of the following commands in the LOGICMOO docker." echo -e "\n lmoo [--no-x] [--no-env] [-v|-q] [--wd ] [--] []\n" echo " clif # Common Logic Interchange Format (with CG/EC)" echo " pfc # Prolog with Forward Chaining " bash -c "cd $ROOT_DIRECTORY ; grep -H '\\#\\-\\-help' . -r | sed -e 's|^./| |1' -e 's/\\#\\-\\-help//1' -e 's/.sh:/$TAB/1' -e 's/lmoo-//g' -e 's/[:]/$TAB/1' " | sort echo -e "\n" } for arg in "$@" do case $arg in --help|-h) show_lm_help return 0 2>/dev/null ; exit 0 ;; --no-x) NOX=1 shift ;; --no-env) LMENV=0 shift ;; -v|-q|-x|-e) LMENV_ARG="${LMENV_ARG} $1" shift ;; -d|--wd) ROOT_DIRECTORY="$2" shift # Remove argument name from processing shift # Remove argument value from processing ;; --) shift break;; *) break;; esac done if [ $LMENV -eq 1 ]; then . /opt/logicmoo_workspace/logicmoo_env.sh $LMENV_ARG fi if [ $NOX -eq 1 ]; then #echo "unset DISPLAY" unset DISPLAY fi cmd="${1}" shift 1 if [ -z "${cmd}" ] || [[ "${cmd}" == "--help" ]]; then show_lm_help return 0 2>/dev/null ; exit 0 fi if [ "${cmd}" == "attach" ]; then STUFF="^Mprolog. call((bfly_set(butterfly),bfly_set(command_args,\"${*}\"),bfly_set(ptty,\"${PTTY}:${TTY}:${PTY}:${PTS}\"))). bfly_start_link(\"${LOCATION}\"). ansi. end_of_file.^M" echo STUFF=$STUFF ( $SCREEN_CMD -S LogicmooServer -p0 -X stuff "${STUFF}" $SCREEN_CMD -rx LogicmooServer ) elif [ -f "$ROOT_DIRECTORY/lmoo-${cmd}" ]; then bash -c "$ROOT_DIRECTORY/lmoo-${cmd} $*" elif [ -f "$ROOT_DIRECTORY/${cmd}.sh" ]; then bash -c "$ROOT_DIRECTORY/${cmd}.sh $*" elif [ -f "$ROOT_DIRECTORY/${cmd}" ]; then bash -c "$ROOT_DIRECTORY/${cmd} $*" else export WHICH=`cd $ROOT_DIRECTORY ; which ${cmd}.sh` if ! [[ -z "${WHICH}" ]]; then bash -c "cd $ROOT_DIRECTORY && $WHICH $*" else #bash -c "cd ~ && $cmd $*" <- why? bash -c "$cmd $*" fi fi return 0 2>/dev/null exit 0