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
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.
2022-11-24 04:51:05 +03:00
: ${ ATOM_DISABLE_SHELLING_OUT_FOR_ENVIRONMENT : =true }
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 =
2022-12-27 18:32:37 +03:00
while getopts ":anwtfvhp-:" 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)
EXPECT_OUTPUT = 1
; ;
2022-12-27 18:32:37 +03:00
foreground| benchmark| benchmark-test| test| package)
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
; ;
2022-12-27 18:32:37 +03:00
f| t| h| v| p)
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
2022-08-17 00:46:39 +03:00
ATOM_HOME = " ${ ATOM_HOME :- $HOME /.pulsar } "
2018-06-05 03:22:59 +03:00
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
2022-12-20 16:11:57 +03:00
ATOM_APP = " $( dirname " $( dirname " $( dirname " $SCRIPT " ) " ) " ) "
2016-10-21 10:34:34 +03:00
if [ " $ATOM_APP " = = . ] ; then
unset ATOM_APP
else
2022-10-02 06:34:43 +03:00
PULSAR_PATH = " $( dirname " $ATOM_APP " ) "
2016-10-21 10:34:34 +03:00
ATOM_APP_NAME = " $( basename " $ATOM_APP " ) "
fi
2022-11-24 04:51:05 +03:00
if [ -n " ${ ATOM_APP_NAME } " ] ; then
2018-07-19 20:53:43 +03:00
# 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
2022-11-24 04:49:19 +03:00
ATOM_EXECUTABLE_NAME = "Pulsar"
2015-09-21 20:38:36 +03:00
fi
2014-03-18 12:27:43 +04:00
2022-10-02 06:34:43 +03:00
if [ -z " ${ PULSAR_PATH } " ] ; then
# If PULSAR_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
2022-10-02 06:34:43 +03:00
PULSAR_PATH = "/Applications"
2015-01-22 07:01:37 +03:00
elif [ -x " $HOME /Applications/ $ATOM_APP_NAME " ] ; then
2022-10-02 06:34:43 +03:00
PULSAR_PATH = " $HOME /Applications "
2015-01-22 07:01:37 +03:00
else
2022-08-17 00:46:39 +03:00
# We haven't found an Pulsar.app, use spotlight to search for Pulsar
2023-03-13 18:18:09 +03:00
PULSAR_PATH = " $( mdfind "kMDItemCFBundleIdentifier == 'dev.pulsar-edit.pulsar'" | grep -v ShipIt | head -1 | xargs -0 dirname) "
2014-03-18 12:27:43 +04:00
2022-08-17 00:46:39 +03:00
# Exit if Pulsar can't be found
2022-10-02 06:34:43 +03:00
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 } . "
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
2022-10-02 06:34:43 +03:00
" $PULSAR_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
2022-12-20 16:11:57 +03:00
open -a " $PULSAR_PATH / $ATOM_APP_NAME " -n -g --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 " )
2014-07-24 20:27:47 +04:00
2022-11-24 04:49:19 +03:00
PULSAR_PATH = "/opt/Pulsar/pulsar"
2015-09-21 20:38:36 +03:00
2016-12-09 19:33:26 +03:00
#Will allow user to get context menu on cinnamon desktop enviroment
2022-11-24 04:51:59 +03:00
#Add a check to make sure that DESKTOP_SESSION is set before attempting to grep it
#expr substr is expecting 3 arguments string, index, length
2022-11-25 21:25:08 +03:00
#If grep doesnt find anything is provides an empty string which causes the expr: syntax error: missing argument after '8' error - see pulsar-edit/pulsar#174
2022-11-24 04:51:59 +03:00
#Im also not quite sure why they used grep instead of simply [ "${DESKTOP_SESSION}" == "cinnamon" ]
if [ -n " ${ DESKTOP_SESSION } " ] && [ " $( expr substr $( printenv | grep 'DESKTOP_SESSION=' ) 17 8) " = = "cinnamon" ] ; then
#This local path is almost assuredly wrong as it shouldnt exist in a standard install
ACTION_PATH = "resources/linux/desktopenviroment/cinnamon/pulsar.nemo_action"
#Validate the file exists before attempting to copy it
if [ -f " ${ ACTION_PATH } " ] ; then
cp " ${ $ACTION_PATH } " "/usr/share/nemo/actions/pulsar.nemo_action"
fi
2016-12-09 19:33:26 +03:00
fi
2022-11-24 04:51:05 +03:00
#Set tmpdir only if tmpdir is unset
2014-05-19 22:26:47 +04:00
: ${ TMPDIR : =/tmp }
2022-10-02 06:34:43 +03:00
[ -x " $PULSAR_PATH " ] || PULSAR_PATH = " $TMPDIR /pulsar-build/Pulsar/pulsar "
2014-03-18 12:27:43 +04:00
if [ $EXPECT_OUTPUT ] ; then
2022-12-25 03:35:03 +03:00
" $PULSAR_PATH " --executed-from= " $( pwd ) " --pid= $$ " $@ " --no-sandbox
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
(
2022-12-25 03:35:03 +03:00
nohup " $PULSAR_PATH " --executed-from= " $( pwd ) " --pid= $$ " $@ " --no-sandbox > " $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
2022-08-17 00:46:39 +03:00
# Exits this process when Pulsar is used as $EDITOR
2013-02-23 08:49:37 +04:00
on_die( ) {
exit 0
}
trap 'on_die' SIGQUIT SIGTERM
2022-08-17 00:46:39 +03:00
# If the wait flag is set, don't exit this process until Pulsar 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