CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Tools/autotest/run_in_terminal_window.sh
Views: 1798
1
#!/usr/bin/env bash
2
3
# Try to run a command in an appropriate type of terminal window
4
# depending on whats available
5
# Sigh: theres no common way of handling command line args :-(
6
name="$1"
7
shift
8
echo "RiTW: Starting $name : $*"
9
10
if [ -z "$SITL_RITW_MINIMIZE" ]; then
11
SITL_RITW_MINIMIZE=1
12
fi
13
14
if [ -n "$SITL_RITW_TERMINAL" ]; then
15
# create a small shell script containing the command to run; this
16
# avoids problems where "screen" expects arguments in
17
# argv[1],argv[2],argv[3] where gnome-terminal expects the command
18
# to run be in argv[n+1] where argv[n] is "-e"
19
# this should work with:
20
# export SITL_RITW_TERMINAL="screen -D -m"
21
# export SITL_RITW_TERMINAL="gnome-terminal -e"
22
# export SITL_RITW_TERMINAL="konsole -e"
23
24
test -z "$TMPDIR" && TMPDIR="/tmp/"
25
FILENAME="ritw-`date '+%Y%m%d%H%M%S'`"
26
FILEPATH="$TMPDIR/$FILENAME"
27
echo "#!/bin/sh" >"$FILEPATH"
28
printf "%q " "$@" >>"$FILEPATH"
29
chmod +x "$FILEPATH"
30
$SITL_RITW_TERMINAL "$FILEPATH" &
31
elif [ -n "$TMUX" ]; then
32
tmux new-window -dn "$name" "$*"
33
elif [ -n "$DISPLAY" -a -n "$(which osascript)" ]; then
34
osascript -e 'tell application "Terminal" to do script "'"cd $(pwd) && clear && $* "'"'
35
elif [ -n "$DISPLAY" -a -n "$(which xterm)" ]; then
36
if [ $SITL_RITW_MINIMIZE -eq 1 ]; then
37
ICONIC=-iconic
38
fi
39
xterm $ICONIC -xrm 'XTerm*selectToClipboard: true' -xrm 'XTerm*initialFont: 6' -n "$name" -name "$name" -T "$name" -hold -e $* &
40
elif [ -n "$DISPLAY" -a -n "$(which konsole)" ]; then
41
konsole --hold -e $*
42
elif [ -n "$DISPLAY" -a -n "$(which gnome-terminal)" ]; then
43
gnome-terminal -e "$*"
44
elif [ -n "$STY" ]; then
45
# We are running inside of screen, try to start it there
46
screen -X screen -t "$name" bash -c "cd $PWD; $*"
47
elif [ -n "$ZELLIJ" ]; then
48
# Create a new pane to run
49
zellij run -n "$name" -- "$1" "${@:2}"
50
else
51
filename="/tmp/$name.log"
52
echo "RiTW: Window access not found, logging to $filename"
53
cmd="$1"
54
shift
55
# the following "true" is to avoid bash optimising the following call
56
# to avoid creating a subshell. We need that subshell, or
57
# _fdm_input_step sees ArduPilot has no parent and kills ArduPilot!
58
( : ; "$cmd" $* &>"$filename" < /dev/null ) &
59
fi
60
exit 0
61
62