Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Tools/autotest/run_in_terminal_window.sh
Views: 1798
#!/usr/bin/env bash12# Try to run a command in an appropriate type of terminal window3# depending on whats available4# Sigh: theres no common way of handling command line args :-(5name="$1"6shift7echo "RiTW: Starting $name : $*"89if [ -z "$SITL_RITW_MINIMIZE" ]; then10SITL_RITW_MINIMIZE=111fi1213if [ -n "$SITL_RITW_TERMINAL" ]; then14# create a small shell script containing the command to run; this15# avoids problems where "screen" expects arguments in16# argv[1],argv[2],argv[3] where gnome-terminal expects the command17# to run be in argv[n+1] where argv[n] is "-e"18# this should work with:19# export SITL_RITW_TERMINAL="screen -D -m"20# export SITL_RITW_TERMINAL="gnome-terminal -e"21# export SITL_RITW_TERMINAL="konsole -e"2223test -z "$TMPDIR" && TMPDIR="/tmp/"24FILENAME="ritw-`date '+%Y%m%d%H%M%S'`"25FILEPATH="$TMPDIR/$FILENAME"26echo "#!/bin/sh" >"$FILEPATH"27printf "%q " "$@" >>"$FILEPATH"28chmod +x "$FILEPATH"29$SITL_RITW_TERMINAL "$FILEPATH" &30elif [ -n "$TMUX" ]; then31tmux new-window -dn "$name" "$*"32elif [ -n "$DISPLAY" -a -n "$(which osascript)" ]; then33osascript -e 'tell application "Terminal" to do script "'"cd $(pwd) && clear && $* "'"'34elif [ -n "$DISPLAY" -a -n "$(which xterm)" ]; then35if [ $SITL_RITW_MINIMIZE -eq 1 ]; then36ICONIC=-iconic37fi38xterm $ICONIC -xrm 'XTerm*selectToClipboard: true' -xrm 'XTerm*initialFont: 6' -n "$name" -name "$name" -T "$name" -hold -e $* &39elif [ -n "$DISPLAY" -a -n "$(which konsole)" ]; then40konsole --hold -e $*41elif [ -n "$DISPLAY" -a -n "$(which gnome-terminal)" ]; then42gnome-terminal -e "$*"43elif [ -n "$STY" ]; then44# We are running inside of screen, try to start it there45screen -X screen -t "$name" bash -c "cd $PWD; $*"46elif [ -n "$ZELLIJ" ]; then47# Create a new pane to run48zellij run -n "$name" -- "$1" "${@:2}"49else50filename="/tmp/$name.log"51echo "RiTW: Window access not found, logging to $filename"52cmd="$1"53shift54# the following "true" is to avoid bash optimising the following call55# to avoid creating a subshell. We need that subshell, or56# _fdm_input_step sees ArduPilot has no parent and kills ArduPilot!57( : ; "$cmd" $* &>"$filename" < /dev/null ) &58fi59exit 0606162