forked from pulsar-edit/pulsar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pulsar.sh
executable file
·178 lines (155 loc) · 4.34 KB
/
pulsar.sh
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/bin/bash
if [ "$(uname)" == 'Darwin' ]; then
OS='Mac'
elif [ "$(expr substr $(uname -s) 1 5)" == 'Linux' ]; then
OS='Linux'
else
echo "Your platform ($(uname -a)) is not supported."
exit 1
fi
# Only set the ATOM_DISABLE_SHELLING_OUT_FOR_ENVIRONMENT env var if it hasn't been set.
if [ -z "$ATOM_DISABLE_SHELLING_OUT_FOR_ENVIRONMENT" ]
then
export ATOM_DISABLE_SHELLING_OUT_FOR_ENVIRONMENT=true
fi
ATOM_ADD=false
ATOM_NEW_WINDOW=false
EXIT_CODE_OVERRIDE=
while getopts ":anwtfvhp-:" opt; do
case "$opt" in
-)
case "${OPTARG}" in
add)
ATOM_ADD=true
;;
new-window)
ATOM_NEW_WINDOW=true
;;
wait)
WAIT=1
;;
help|version)
EXPECT_OUTPUT=1
;;
foreground|benchmark|benchmark-test|test|package)
EXPECT_OUTPUT=1
;;
enable-electron-logging)
export ELECTRON_ENABLE_LOGGING=1
;;
esac
;;
a)
ATOM_ADD=true
;;
n)
ATOM_NEW_WINDOW=true
;;
w)
WAIT=1
;;
f|t|h|v|p)
EXPECT_OUTPUT=1
;;
esac
done
if [ "${ATOM_ADD}" = "true" ] && [ "${ATOM_NEW_WINDOW}" = "true" ]; then
EXPECT_OUTPUT=1
EXIT_CODE_OVERRIDE=1
fi
if [ $REDIRECT_STDERR ]; then
exec 2> /dev/null
fi
ATOM_HOME="${ATOM_HOME:-$HOME/.pulsar}"
mkdir -p "$ATOM_HOME"
if [ $OS == 'Mac' ]; then
if [ -L "$0" ]; then
SCRIPT="$(readlink "$0")"
else
SCRIPT="$0"
fi
ATOM_APP="$(dirname "$(dirname "$(dirname "$SCRIPT")")")"
if [ "$ATOM_APP" == . ]; then
unset ATOM_APP
else
PULSAR_PATH="$(dirname "$ATOM_APP")"
ATOM_APP_NAME="$(basename "$ATOM_APP")"
fi
if [ -n "${ATOM_APP_NAME}" ]; then
# If ATOM_APP_NAME is known, use it as the executable name
ATOM_EXECUTABLE_NAME="${ATOM_APP_NAME%.*}"
else
# Else choose it from the inferred channel name
ATOM_EXECUTABLE_NAME="Pulsar"
fi
if [ -z "${PULSAR_PATH}" ]; then
# If PULSAR_PATH isn't set, check /Applications and then ~/Applications for Atom.app
if [ -x "/Applications/$ATOM_APP_NAME" ]; then
PULSAR_PATH="/Applications"
elif [ -x "$HOME/Applications/$ATOM_APP_NAME" ]; then
PULSAR_PATH="$HOME/Applications"
else
# We haven't found an Pulsar.app, use spotlight to search for Pulsar
PULSAR_PATH="$(mdfind "kMDItemCFBundleIdentifier == 'dev.pulsar-edit.pulsar'" | grep -v ShipIt | head -1 | xargs -0 dirname)"
# Exit if Pulsar can't be found
if [ ! -x "$PULSAR_PATH/$ATOM_APP_NAME" ]; then
echo "Cannot locate ${ATOM_APP_NAME}, it is usually located in /Applications. Set the PULSAR_PATH environment variable to the directory containing ${ATOM_APP_NAME}."
exit 1
fi
fi
fi
if [ $EXPECT_OUTPUT ]; then
"$PULSAR_PATH/$ATOM_APP_NAME/Contents/MacOS/$ATOM_EXECUTABLE_NAME" --executed-from="$(pwd)" --pid=$$ "$@"
ATOM_EXIT=$?
if [ ${ATOM_EXIT} -eq 0 ] && [ -n "${EXIT_CODE_OVERRIDE}" ]; then
exit "${EXIT_CODE_OVERRIDE}"
else
exit ${ATOM_EXIT}
fi
else
open -a "$PULSAR_PATH/$ATOM_APP_NAME" -n -g --args --executed-from="$(pwd)" --pid=$$ --path-environment="$PATH" "$@"
fi
elif [ $OS == 'Linux' ]; then
SCRIPT=$(readlink -f "$0")
PULSAR_PATH="/opt/Pulsar/pulsar"
#Set tmpdir only if tmpdir is unset
: ${TMPDIR:=/tmp}
[ -x "$PULSAR_PATH" ] || PULSAR_PATH="$TMPDIR/pulsar-build/Pulsar/pulsar"
if [ $EXPECT_OUTPUT ]; then
"$PULSAR_PATH" --executed-from="$(pwd)" --pid=$$ "$@" --no-sandbox
ATOM_EXIT=$?
if [ ${ATOM_EXIT} -eq 0 ] && [ -n "${EXIT_CODE_OVERRIDE}" ]; then
exit "${EXIT_CODE_OVERRIDE}"
else
exit ${ATOM_EXIT}
fi
else
(
nohup "$PULSAR_PATH" --executed-from="$(pwd)" --pid=$$ "$@" --no-sandbox > "$ATOM_HOME/nohup.out" 2>&1
if [ $? -ne 0 ]; then
cat "$ATOM_HOME/nohup.out"
exit $?
fi
) &
fi
fi
# Exits this process when Pulsar is used as $EDITOR
on_die() {
exit 0
}
trap 'on_die' SIGQUIT SIGTERM
# If the wait flag is set, don't exit this process until Pulsar kills it.
if [ $WAIT ]; then
WAIT_FIFO="$ATOM_HOME/.wait_fifo"
if [ ! -p "$WAIT_FIFO" ]; then
rm -f "$WAIT_FIFO"
mkfifo "$WAIT_FIFO"
fi
# Block endlessly by reading from a named pipe.
exec 2>/dev/null
read < "$WAIT_FIFO"
# If the read completes for some reason, fall back to sleeping in a loop.
while true; do
sleep 1
done
fi