2014-03-18 12:27:43 +04: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'
|
2014-05-10 16:15:53 +04:00
|
|
|
elif [ "$(expr substr $(uname -s) 1 10)" == 'MINGW32_NT' ]; then
|
2014-03-18 12:27:43 +04:00
|
|
|
OS='Cygwin'
|
|
|
|
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
|
|
|
|
|
2014-05-10 15:41:30 +04:00
|
|
|
while getopts ":wtfvh-:" opt; do
|
2013-08-08 04:00:09 +04:00
|
|
|
case "$opt" in
|
|
|
|
-)
|
|
|
|
case "${OPTARG}" in
|
|
|
|
wait)
|
|
|
|
WAIT=1
|
|
|
|
;;
|
2014-03-14 01:59:52 +04:00
|
|
|
help|version)
|
|
|
|
REDIRECT_STDERR=1
|
|
|
|
EXPECT_OUTPUT=1
|
|
|
|
;;
|
|
|
|
foreground|test)
|
2013-08-08 04:00:09 +04:00
|
|
|
EXPECT_OUTPUT=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
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
|
|
|
|
|
2014-03-14 01:59:52 +04:00
|
|
|
if [ $REDIRECT_STDERR ]; then
|
|
|
|
exec 2> /dev/null
|
|
|
|
fi
|
|
|
|
|
2014-03-18 12:27:43 +04:00
|
|
|
if [ $OS == 'Mac' ]; then
|
|
|
|
ATOM_PATH=${ATOM_PATH:-/Applications} # Set ATOM_PATH unless it is already set
|
|
|
|
ATOM_APP_NAME=Atom.app
|
|
|
|
|
|
|
|
# If ATOM_PATH isn't a executable file, use spotlight to search for Atom
|
|
|
|
if [ ! -x "$ATOM_PATH/$ATOM_APP_NAME" ]; then
|
|
|
|
ATOM_PATH=$(mdfind "kMDItemCFBundleIdentifier == 'com.github.atom'" | head -1 | xargs dirname)
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Exit if Atom can't be found
|
|
|
|
if [ -z "$ATOM_PATH" ]; then
|
|
|
|
echo "Cannot locate Atom.app, it is usually located in /Applications. Set the ATOM_PATH environment variable to the directory containing Atom.app."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $EXPECT_OUTPUT ]; then
|
|
|
|
"$ATOM_PATH/$ATOM_APP_NAME/Contents/MacOS/Atom" --executed-from="$(pwd)" --pid=$$ "$@"
|
|
|
|
exit $?
|
|
|
|
else
|
|
|
|
open -a "$ATOM_PATH/$ATOM_APP_NAME" -n --args --executed-from="$(pwd)" --pid=$$ "$@"
|
|
|
|
fi
|
|
|
|
elif [ $OS == 'Linux' ]; then
|
2014-05-10 16:15:53 +04:00
|
|
|
SCRIPT=$(readlink -f "$0")
|
|
|
|
USR_DIRECTORY=$(readlink -f $(dirname $SCRIPT)/..)
|
2014-03-20 18:01:23 +04:00
|
|
|
ATOM_PATH="$USR_DIRECTORY/share/atom/atom"
|
|
|
|
|
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=$$ "$@"
|
|
|
|
exit $?
|
|
|
|
else
|
2014-05-06 20:21:01 +04:00
|
|
|
(
|
2014-05-19 22:26:47 +04:00
|
|
|
nohup "$ATOM_PATH" --executed-from="$(pwd)" --pid=$$ "$@" > "$TMPDIR/atom-nohup.out" 2>&1
|
2014-05-06 20:21:01 +04:00
|
|
|
if [ $? -ne 0 ]; then
|
2014-05-19 22:26:47 +04:00
|
|
|
cat "$TMPDIR/atom-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
|
|
|
|
|
2014-03-13 22:14:26 +04:00
|
|
|
# If the wait flag is set, don't exit this process until Atom tells it to.
|
2013-02-23 08:49:37 +04:00
|
|
|
if [ $WAIT ]; then
|
|
|
|
while true; do
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
fi
|