-
Notifications
You must be signed in to change notification settings - Fork 7
/
modman.command
55 lines (46 loc) · 1.22 KB
/
modman.command
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/sh
# Get the script's name.
me=$(basename "$0");
# Get the absolute path to this script's folder.
if echo "$0" | awk '{exit(!/^\//);}'; then
maindir=$(dirname "$0");
else
maindir=$PWD/$(dirname "$0");
fi
# Spawn a terminal if this is headless (or piped) and not on an ssh socket.
# The terminal will run another instance of this script with ${ingui}=1.
if [ ! \( -t 0 -o -S /dev/stdin \) ]; then
if [ "${ingui}" = "1" ]; then
echo "This is a nested instance. The terminal must have spawned.";
echo "Yet the 'Am I headless' test couldn't detect the terminal!?";
exit
fi
echo "Double-clicked? You need a terminal!";
export ingui=1;
if command -v x-terminal-emulator >/dev/null; then
# Linux.
x-terminal-emulator -e "$0";
elif command -v osascript >/dev/null; then
# OSX.
# *.command files normally get their own terminal there,
# but better safe than sorry.
# - - -
osascript <<EOF
tell application "Terminal"
activate
do script "export ingui=1;cd \"${maindir}\";\"./${me}\";exit"
end tell
EOF
# - - -
fi
exit;
fi
# Finally, the payload.
cd "${maindir}"
# - - -
python main.py
# - - -
if [ "${ingui}" = "1" ]; then
read -p "Press enter to continue" dummyvar
fi
exit;