2015-06-03 04:28:33 +03:00
#!/bin/bash
2013-04-18 03:24:40 +04:00
2014-05-10 16:15:53 +04:00
if [ " $( uname) " = = 'Darwin' ] ; then
2014-03-18 12:27:43 +04:00
OS = 'Mac'
2014-05-10 16:15:53 +04:00
elif [ " $( expr substr $( uname -s) 1 5) " = = 'Linux' ] ; then
2014-03-18 12:27:43 +04:00
OS = 'Linux'
else
2014-05-10 16:15:53 +04:00
echo " Your platform ( $( uname -a) ) is not supported. "
2013-04-18 03:25:03 +04:00
exit 1
fi
2017-08-30 06:56:51 +03:00
case $( basename $0 ) in
atom-beta)
CHANNEL = beta
; ;
2018-06-27 02:48:36 +03:00
atom-nightly)
CHANNEL = nightly
; ;
2017-08-30 06:56:51 +03:00
atom-dev)
CHANNEL = dev
; ;
*)
CHANNEL = stable
; ;
esac
2015-09-21 20:38:36 +03:00
2019-04-11 18:10:38 +03:00
# 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
2016-08-31 09:07:15 +03:00
2019-03-22 18:29:21 +03:00
ATOM_ADD = false
ATOM_NEW_WINDOW = false
EXIT_CODE_OVERRIDE =
while getopts ":anwtfvh-:" opt; do
2013-08-08 04:00:09 +04:00
case " $opt " in
-)
case " ${ OPTARG } " in
2019-03-22 18:29:21 +03:00
add)
ATOM_ADD = true
; ;
new-window)
ATOM_NEW_WINDOW = true
; ;
2013-08-08 04:00:09 +04:00
wait )
WAIT = 1
; ;
2014-03-14 01:59:52 +04:00
help| version)
REDIRECT_STDERR = 1
EXPECT_OUTPUT = 1
; ;
2016-10-13 18:09:54 +03:00
foreground| benchmark| benchmark-test| test )
2013-08-08 04:00:09 +04:00
EXPECT_OUTPUT = 1
; ;
2017-08-03 06:03:29 +03:00
enable-electron-logging)
export ELECTRON_ENABLE_LOGGING = 1
; ;
2013-08-08 04:00:09 +04:00
esac
; ;
2019-03-22 18:29:21 +03:00
a)
ATOM_ADD = true
; ;
n)
ATOM_NEW_WINDOW = true
; ;
2013-08-08 04:00:09 +04:00
w)
WAIT = 1
; ;
2014-03-14 01:59:52 +04:00
h| v)
REDIRECT_STDERR = 1
EXPECT_OUTPUT = 1
; ;
f| t)
2013-08-08 04:00:09 +04:00
EXPECT_OUTPUT = 1
; ;
esac
done
2019-03-22 18:29:21 +03:00
if [ " ${ ATOM_ADD } " = "true" ] && [ " ${ ATOM_NEW_WINDOW } " = "true" ] ; then
EXPECT_OUTPUT = 1
EXIT_CODE_OVERRIDE = 1
fi
2014-03-14 01:59:52 +04:00
if [ $REDIRECT_STDERR ] ; then
exec 2> /dev/null
fi
2018-06-05 03:22:59 +03:00
ATOM_HOME = " ${ ATOM_HOME :- $HOME /.atom } "
mkdir -p " $ATOM_HOME "
2014-03-18 12:27:43 +04:00
if [ $OS = = 'Mac' ] ; then
2016-10-24 19:38:34 +03:00
if [ -L " $0 " ] ; then
SCRIPT = " $( readlink " $0 " ) "
else
SCRIPT = " $0 "
fi
ATOM_APP = " $( dirname " $( dirname " $( dirname " $( dirname " $SCRIPT " ) " ) " ) " ) "
2016-10-21 10:34:34 +03:00
if [ " $ATOM_APP " = = . ] ; then
unset ATOM_APP
else
ATOM_PATH = " $( dirname " $ATOM_APP " ) "
ATOM_APP_NAME = " $( basename " $ATOM_APP " ) "
fi
2018-07-19 20:53:43 +03:00
if [ ! -z " ${ ATOM_APP_NAME } " ] ; then
# If ATOM_APP_NAME is known, use it as the executable name
ATOM_EXECUTABLE_NAME = " ${ ATOM_APP_NAME %.* } "
2015-09-21 20:38:36 +03:00
else
2018-07-19 20:53:43 +03:00
# Else choose it from the inferred channel name
if [ " $CHANNEL " = = 'beta' ] ; then
ATOM_EXECUTABLE_NAME = "Atom Beta"
elif [ " $CHANNEL " = = 'nightly' ] ; then
ATOM_EXECUTABLE_NAME = "Atom Nightly"
elif [ " $CHANNEL " = = 'dev' ] ; then
ATOM_EXECUTABLE_NAME = "Atom Dev"
else
ATOM_EXECUTABLE_NAME = "Atom"
fi
2015-09-21 20:38:36 +03:00
fi
2014-03-18 12:27:43 +04:00
2015-01-22 07:01:37 +03:00
if [ -z " ${ ATOM_PATH } " ] ; then
2016-12-27 18:39:24 +03:00
# If ATOM_PATH isn't set, check /Applications and then ~/Applications for Atom.app
2015-01-22 07:01:37 +03:00
if [ -x " /Applications/ $ATOM_APP_NAME " ] ; then
ATOM_PATH = "/Applications"
elif [ -x " $HOME /Applications/ $ATOM_APP_NAME " ] ; then
ATOM_PATH = " $HOME /Applications "
else
2016-12-27 18:39:24 +03:00
# We haven't found an Atom.app, use spotlight to search for Atom
2015-01-22 07:01:37 +03:00
ATOM_PATH = " $( mdfind "kMDItemCFBundleIdentifier == 'com.github.atom'" | grep -v ShipIt | head -1 | xargs -0 dirname) "
2014-03-18 12:27:43 +04:00
2015-01-22 07:01:37 +03:00
# Exit if Atom can't be found
if [ ! -x " $ATOM_PATH / $ATOM_APP_NAME " ] ; then
2016-12-27 18:39:24 +03:00
echo " Cannot locate ${ ATOM_APP_NAME } , it is usually located in /Applications. Set the ATOM_PATH environment variable to the directory containing ${ ATOM_APP_NAME } . "
2015-01-22 07:01:37 +03:00
exit 1
fi
fi
2014-03-18 12:27:43 +04:00
fi
if [ $EXPECT_OUTPUT ] ; then
2016-08-30 20:25:09 +03:00
" $ATOM_PATH / $ATOM_APP_NAME /Contents/MacOS/ $ATOM_EXECUTABLE_NAME " --executed-from= " $( pwd ) " --pid= $$ " $@ "
2019-03-28 16:59:13 +03:00
ATOM_EXIT = $?
if [ ${ ATOM_EXIT } -eq 0 ] && [ -n " ${ EXIT_CODE_OVERRIDE } " ] ; then
2019-03-22 18:29:21 +03:00
exit " ${ EXIT_CODE_OVERRIDE } "
else
2019-03-28 16:59:13 +03:00
exit ${ ATOM_EXIT }
2019-03-22 18:29:21 +03:00
fi
2014-03-18 12:27:43 +04:00
else
2014-11-05 07:11:42 +03:00
open -a " $ATOM_PATH / $ATOM_APP_NAME " -n --args --executed-from= " $( pwd ) " --pid= $$ --path-environment= " $PATH " " $@ "
2014-03-18 12:27:43 +04:00
fi
elif [ $OS = = 'Linux' ] ; then
2014-05-10 16:15:53 +04:00
SCRIPT = $( readlink -f " $0 " )
USR_DIRECTORY = $( readlink -f $( dirname $SCRIPT ) /..)
2014-07-24 20:27:47 +04:00
2017-08-30 06:56:51 +03:00
case $CHANNEL in
beta)
ATOM_PATH = " $USR_DIRECTORY /share/atom-beta/atom "
; ;
2018-06-27 02:48:36 +03:00
nightly)
ATOM_PATH = " $USR_DIRECTORY /share/atom-nightly/atom "
; ;
2017-08-30 06:56:51 +03:00
dev)
ATOM_PATH = " $USR_DIRECTORY /share/atom-dev/atom "
; ;
*)
ATOM_PATH = " $USR_DIRECTORY /share/atom/atom "
; ;
esac
2015-09-21 20:38:36 +03:00
2014-05-19 22:26:47 +04:00
: ${ TMPDIR : =/tmp }
[ -x " $ATOM_PATH " ] || ATOM_PATH = " $TMPDIR /atom-build/Atom/atom "
2014-03-18 12:27:43 +04:00
if [ $EXPECT_OUTPUT ] ; then
" $ATOM_PATH " --executed-from= " $( pwd ) " --pid= $$ " $@ "
2019-03-28 16:59:13 +03:00
ATOM_EXIT = $?
if [ ${ ATOM_EXIT } -eq 0 ] && [ -n " ${ EXIT_CODE_OVERRIDE } " ] ; then
2019-03-22 18:29:21 +03:00
exit " ${ EXIT_CODE_OVERRIDE } "
else
2019-03-28 16:59:13 +03:00
exit ${ ATOM_EXIT }
2019-03-22 18:29:21 +03:00
fi
2014-03-18 12:27:43 +04:00
else
2014-05-06 20:21:01 +04:00
(
2015-02-04 03:27:18 +03:00
nohup " $ATOM_PATH " --executed-from= " $( pwd ) " --pid= $$ " $@ " > " $ATOM_HOME /nohup.out " 2>& 1
2014-05-06 20:21:01 +04:00
if [ $? -ne 0 ] ; then
2015-02-04 03:27:18 +03:00
cat " $ATOM_HOME /nohup.out "
2014-05-06 20:21:01 +04:00
exit $?
fi
) &
2014-03-18 12:27:43 +04:00
fi
2013-08-08 04:00:09 +04:00
fi
2013-02-23 08:49:37 +04:00
2014-03-13 22:14:26 +04:00
# Exits this process when Atom is used as $EDITOR
2013-02-23 08:49:37 +04:00
on_die( ) {
exit 0
}
trap 'on_die' SIGQUIT SIGTERM
2018-06-05 19:59:25 +03:00
# If the wait flag is set, don't exit this process until Atom kills it.
2013-02-23 08:49:37 +04:00
if [ $WAIT ] ; then
2018-05-29 23:37:15 +03:00
WAIT_FIFO = " $ATOM_HOME /.wait_fifo "
2018-06-05 03:22:59 +03:00
2018-06-05 19:59:25 +03:00
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.
2013-02-23 08:49:37 +04:00
while true; do
sleep 1
done
fi