From ed1e070bdb59819631384f798d677dd88bfee8a2 Mon Sep 17 00:00:00 2001 From: Andrew Dupont Date: Fri, 26 Jul 2024 16:03:39 -0700 Subject: [PATCH 1/7] =?UTF-8?q?Experiment:=20Redirect=20`-p`/`--package`?= =?UTF-8?q?=20to=20`ppm`=20via=20`pulsar.sh`=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …plus some other fixes for Linux and macOS. --- pulsar.sh | 96 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 83 insertions(+), 13 deletions(-) diff --git a/pulsar.sh b/pulsar.sh index e3dab18cd9..321efa3a7f 100755 --- a/pulsar.sh +++ b/pulsar.sh @@ -1,5 +1,22 @@ #!/bin/bash +echoerr() { echo "$@" 1>&2; } + +# Given a list of arguments, reduces them to the subset that follow the first +# occurrence of `-p` or `--package`. These are the arguments that will be +# passed to `ppm`. +shift_args_for_package_mode() { + loop_done=0 + while [ $loop_done -eq 0 ] + do + if [[ "$1" == "-p" || "$1" == "--package" || "$1" == "" ]]; then + # We'll shift one last time and then we'll be done. + loop_done=1 + fi + shift + done +} + if [ "$(uname)" == 'Darwin' ]; then OS='Mac' elif [ "$(expr substr $(uname -s) 1 5)" == 'Linux' ]; then @@ -35,9 +52,12 @@ while getopts ":anwtfvhp-:" opt; do help|version) EXPECT_OUTPUT=1 ;; - foreground|benchmark|benchmark-test|test|package) + foreground|benchmark|benchmark-test|test) EXPECT_OUTPUT=1 ;; + package) + PACKAGE_MODE=1 + ;; enable-electron-logging) export ELECTRON_ENABLE_LOGGING=1 ;; @@ -52,7 +72,10 @@ while getopts ":anwtfvhp-:" opt; do w) WAIT=1 ;; - f|t|h|v|p) + p) + PACKAGE_MODE=1 + ;; + f|t|h|v) EXPECT_OUTPUT=1 ;; esac @@ -95,25 +118,38 @@ if [ $OS == 'Mac' ]; then fi if [ -z "${PULSAR_PATH}" ]; then - # If PULSAR_PATH isn't set, check /Applications and then ~/Applications for Atom.app + # If PULSAR_PATH isn't set, check /Applications and then ~/Applications for Pulsar.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}." + # We still haven't found a Pulsar.app; use Spotlight to Search for Pulsar. + PULSAR_APP_SEARCH_RESULT="$(mdfind "kMDItemCFBundleIdentifier == 'dev.pulsar-edit.pulsar'" | grep -v ShipIt | head -1)" + PULSAR_PATH="$(dirname "$PULSAR_APP_SEARCH_RESULT")" + ATOM_APP_NAME="$(basename "$PULSAR_APP_SEARCH_RESULT")" + + # Exit if Pulsar can't be found. + if [ ! -x "$PULSAR_PATH/${ATOM_APP_NAME:-Pulsar.app}" ]; then + echoerr "Cannot locate ${ATOM_APP_NAME:-Pulsar.app}; it is usually located in /Applications. Set the PULSAR_PATH environment variable to the directory containing ${ATOM_APP_NAME:-Pulsar.app}." exit 1 fi fi fi + PULSAR_EXECUTABLE="$PULSAR_PATH/$ATOM_APP_NAME/Contents/MacOS/$ATOM_EXECUTABLE_NAME" + PPM_EXECUTABLE="$PULSAR_PATH/$ATOM_APP_NAME/Contents/Resources/app/ppm/bin/ppm" + + # If `-p` or `--package` was specified, call `ppm` with all the arguments + # that followed it instead of calling the Pulsar executable directly. + if [ $PACKAGE_MODE ]; then + shift_args_for_package_mode + "$PPM_EXECUTABLE" "$@" + exit $? + fi + if [ $EXPECT_OUTPUT ]; then - "$PULSAR_PATH/$ATOM_APP_NAME/Contents/MacOS/$ATOM_EXECUTABLE_NAME" --executed-from="$(pwd)" --pid=$$ "$@" + "$PULSAR_EXECUTABLE" --executed-from="$(pwd)" --pid=$$ "$@" ATOM_EXIT=$? if [ ${ATOM_EXIT} -eq 0 ] && [ -n "${EXIT_CODE_OVERRIDE}" ]; then exit "${EXIT_CODE_OVERRIDE}" @@ -124,14 +160,48 @@ if [ $OS == 'Mac' ]; then open -a "$PULSAR_PATH/$ATOM_APP_NAME" -n -g --args --executed-from="$(pwd)" --pid=$$ --path-environment="$PATH" "$@" fi elif [ $OS == 'Linux' ]; then + + if [ -L "$0" ]; then + SCRIPT="$(readlink -f "$0")" + else + SCRIPT="$0" + fi + + # Attempt to infer the installation directory of Pulsar from the location of + # this script. SCRIPT=$(readlink -f "$0") + ATOM_APP="$(dirname "$(dirname "$(dirname "$SCRIPT")")")" - PULSAR_PATH="/opt/Pulsar/pulsar" + if [ "$ATOM_APP" == . ]; then + unset ATOM_APP + else + PULSAR_PATH="$(dirname "$ATOM_APP")/pulsar" + fi - #Set tmpdir only if tmpdir is unset + # Set tmpdir only if it's unset. : ${TMPDIR:=/tmp} - [ -x "$PULSAR_PATH" ] || PULSAR_PATH="$TMPDIR/pulsar-build/Pulsar/pulsar" + if [ -n "$PULSAR_PATH" ]; then + if [ -d "/opt/Pulsar/pulsar" ]; then + PULSAR_PATH="/opt/Pulsar/pulsar" + elif [ -d "$TMPDIR/pulsar-build/Pulsar/pulsar" ]; then + PULSAR_PATH="$TMPDIR/pulsar-build/Pulsar/pulsar" + else + : "${ATOM_APP_NAME:=Pulsar}" + echoerr "Cannot locate Pulsar. Set the PULSAR_PATH environment variable to the directory containing the \`pulsar\` executable." + exit 1 + fi + fi + + PPM_PATH="$(dirname "$PULSAR_PATH")/resources/app/ppm/bin/ppm" + + # If `-p` or `--package` was specified, call `ppm` with all the arguments + # that followed it instead of calling the Pulsar executable directly. + if [ $PACKAGE_MODE ]; then + shift_args_for_package_mode + "$PPM_PATH" "$@" + exit $? + fi if [ $EXPECT_OUTPUT ]; then "$PULSAR_PATH" --executed-from="$(pwd)" --pid=$$ "$@" --no-sandbox From 9179a7d1594c92cf2181612cbd3040951aa73961 Mon Sep 17 00:00:00 2001 From: Andrew Dupont Date: Fri, 26 Jul 2024 17:05:42 -0700 Subject: [PATCH 2/7] =?UTF-8?q?Improve=20the=20process=20of=20locating=20P?= =?UTF-8?q?ulsar=20within=20`pulsar.sh`=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …and ensure that the user can always specify `PULSAR_PATH` to supersede this logic. --- pulsar.sh | 103 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 59 insertions(+), 44 deletions(-) diff --git a/pulsar.sh b/pulsar.sh index 321efa3a7f..6a8a92018a 100755 --- a/pulsar.sh +++ b/pulsar.sh @@ -22,7 +22,7 @@ if [ "$(uname)" == 'Darwin' ]; then elif [ "$(expr substr $(uname -s) 1 5)" == 'Linux' ]; then OS='Linux' else - echo "Your platform ($(uname -a)) is not supported." + echoerr "Your platform ($(uname -a)) is not supported." exit 1 fi @@ -99,40 +99,40 @@ if [ $OS == 'Mac' ]; then else SCRIPT="$0" fi - ATOM_APP="$(dirname "$(dirname "$(dirname "$SCRIPT")")")" - if [ "$ATOM_APP" == . ]; then + # If this is a `pulsar.sh` from a built version of Pulsar, then `$ATOM_APP` + # should now be the path to the user's instance of Pulsar.app. + if [[ "$ATOM_APP" == . || "$ATOM_APP" != *".app" ]]; then + # This is a `pulsar.sh` that's in the source code of Pulsar or has been + # copied to a location outside of the app (instead of symlinked). We'll try + # another tactic. unset ATOM_APP else + # We found the location of the Pulsar.app that this script lives in. 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 + # Fall back to the default Pulsar.app as the app name. + ATOM_APP_NAME=${ATOM_APP_NAME:-Pulsar.app} + # The executable name will be the same thing but without the `.app` suffix. + ATOM_EXECUTABLE_NAME="${ATOM_APP_NAME%.*}" if [ -z "${PULSAR_PATH}" ]; then - # If PULSAR_PATH isn't set, check /Applications and then ~/Applications for Pulsar.app - if [ -x "/Applications/$ATOM_APP_NAME" ]; then + # If PULSAR_PATH isn't set, check /Applications and then ~/Applications for + # Pulsar.app. + if [ -x "/Applications/${ATOM_APP_NAME}" ]; then PULSAR_PATH="/Applications" - elif [ -x "$HOME/Applications/$ATOM_APP_NAME" ]; then + elif [ -x "$HOME/Applications/${ATOM_APP_NAME}" ]; then PULSAR_PATH="$HOME/Applications" else - # We still haven't found a Pulsar.app; use Spotlight to Search for Pulsar. + # We still haven't found a Pulsar.app. Let's try searching for it via + # Spotlight. PULSAR_APP_SEARCH_RESULT="$(mdfind "kMDItemCFBundleIdentifier == 'dev.pulsar-edit.pulsar'" | grep -v ShipIt | head -1)" - PULSAR_PATH="$(dirname "$PULSAR_APP_SEARCH_RESULT")" - ATOM_APP_NAME="$(basename "$PULSAR_APP_SEARCH_RESULT")" - - # Exit if Pulsar can't be found. - if [ ! -x "$PULSAR_PATH/${ATOM_APP_NAME:-Pulsar.app}" ]; then - echoerr "Cannot locate ${ATOM_APP_NAME:-Pulsar.app}; it is usually located in /Applications. Set the PULSAR_PATH environment variable to the directory containing ${ATOM_APP_NAME:-Pulsar.app}." - exit 1 + if [ ! -z "$PULSAR_APP_SEARCH_RESULT" ]; then + PULSAR_PATH="$(dirname "$PULSAR_APP_SEARCH_RESULT")" + ATOM_APP_NAME="$(basename "$PULSAR_APP_SEARCH_RESULT")" fi fi fi @@ -140,6 +140,12 @@ if [ $OS == 'Mac' ]; then PULSAR_EXECUTABLE="$PULSAR_PATH/$ATOM_APP_NAME/Contents/MacOS/$ATOM_EXECUTABLE_NAME" PPM_EXECUTABLE="$PULSAR_PATH/$ATOM_APP_NAME/Contents/Resources/app/ppm/bin/ppm" + # Exit if Pulsar can't be found. + if [ ! -x "${PULSAR_EXECUTABLE}" ]; then + echoerr "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 + # If `-p` or `--package` was specified, call `ppm` with all the arguments # that followed it instead of calling the Pulsar executable directly. if [ $PACKAGE_MODE ]; then @@ -167,44 +173,53 @@ elif [ $OS == 'Linux' ]; then SCRIPT="$0" fi - # Attempt to infer the installation directory of Pulsar from the location of - # this script. - SCRIPT=$(readlink -f "$0") - ATOM_APP="$(dirname "$(dirname "$(dirname "$SCRIPT")")")" - - if [ "$ATOM_APP" == . ]; then - unset ATOM_APP - else - PULSAR_PATH="$(dirname "$ATOM_APP")/pulsar" - fi - # Set tmpdir only if it's unset. : ${TMPDIR:=/tmp} - if [ -n "$PULSAR_PATH" ]; then - if [ -d "/opt/Pulsar/pulsar" ]; then - PULSAR_PATH="/opt/Pulsar/pulsar" - elif [ -d "$TMPDIR/pulsar-build/Pulsar/pulsar" ]; then - PULSAR_PATH="$TMPDIR/pulsar-build/Pulsar/pulsar" + ATOM_EXECUTABLE_NAME="pulsar" + + # If `PULSAR_PATH` is set by the user, we'll assume they know what they're + # doing. Otherwise we should try to find it ourselves. + if [ -z "${PULSAR_PATH}" ]; then + # Attempt to infer the installation directory of Pulsar from the location of + # this script. When symlinked + SCRIPT=$(readlink -f "$0") + ATOM_APP="$(dirname "$(dirname "$(dirname "$SCRIPT")")")" + + if [ "$ATOM_APP" == . ]; then + unset ATOM_APP else - : "${ATOM_APP_NAME:=Pulsar}" - echoerr "Cannot locate Pulsar. Set the PULSAR_PATH environment variable to the directory containing the \`pulsar\` executable." - exit 1 + PULSAR_PATH="$(dirname "$ATOM_APP")" + fi + + if [ -z "${PULSAR_PATH}" ]; then + if [ -d "/opt/Pulsar/pulsar" ]; then + # Check the default installation directory for RPM and DEB + # distributions. + PULSAR_PATH="/opt/Pulsar" + elif [ -d "$TMPDIR/pulsar-build/Pulsar/pulsar" ]; then + # This is where Pulsar can be found during some CI build tasks. + PULSAR_PATH="$TMPDIR/pulsar-build/Pulsar" + else + echoerr "Cannot locate Pulsar. Set the PULSAR_PATH environment variable to the directory containing the \`pulsar\` executable." + exit 1 + fi fi fi - PPM_PATH="$(dirname "$PULSAR_PATH")/resources/app/ppm/bin/ppm" + PULSAR_EXECUTABLE="$PULSAR_PATH/$ATOM_EXECUTABLE" + PPM_EXECUTABLE="$(dirname "$PULSAR_PATH")/resources/app/ppm/bin/ppm" # If `-p` or `--package` was specified, call `ppm` with all the arguments # that followed it instead of calling the Pulsar executable directly. if [ $PACKAGE_MODE ]; then shift_args_for_package_mode - "$PPM_PATH" "$@" + "$PPM_EXECUTABLE" "$@" exit $? fi if [ $EXPECT_OUTPUT ]; then - "$PULSAR_PATH" --executed-from="$(pwd)" --pid=$$ "$@" --no-sandbox + "$PULSAR_EXECUTABLE" --executed-from="$(pwd)" --pid=$$ "$@" --no-sandbox ATOM_EXIT=$? if [ ${ATOM_EXIT} -eq 0 ] && [ -n "${EXIT_CODE_OVERRIDE}" ]; then exit "${EXIT_CODE_OVERRIDE}" @@ -213,7 +228,7 @@ elif [ $OS == 'Linux' ]; then fi else ( - nohup "$PULSAR_PATH" --executed-from="$(pwd)" --pid=$$ "$@" --no-sandbox > "$ATOM_HOME/nohup.out" 2>&1 + nohup "$PULSAR_EXECUTABLE" --executed-from="$(pwd)" --pid=$$ "$@" --no-sandbox > "$ATOM_HOME/nohup.out" 2>&1 if [ $? -ne 0 ]; then cat "$ATOM_HOME/nohup.out" exit $? From 29f26c607b109c71e382ec36981942cb44fda541 Mon Sep 17 00:00:00 2001 From: Andrew Dupont Date: Fri, 26 Jul 2024 17:19:41 -0700 Subject: [PATCH 3/7] Fix detection logic on Linux --- pulsar.sh | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/pulsar.sh b/pulsar.sh index 6a8a92018a..a1af505af1 100755 --- a/pulsar.sh +++ b/pulsar.sh @@ -181,15 +181,22 @@ elif [ $OS == 'Linux' ]; then # If `PULSAR_PATH` is set by the user, we'll assume they know what they're # doing. Otherwise we should try to find it ourselves. if [ -z "${PULSAR_PATH}" ]; then - # Attempt to infer the installation directory of Pulsar from the location of - # this script. When symlinked - SCRIPT=$(readlink -f "$0") - ATOM_APP="$(dirname "$(dirname "$(dirname "$SCRIPT")")")" + # Attempt to infer the installation directory of Pulsar from the location + # of this script. When symlinked to a common location like + # `/usr/local/bin`, this approach should find the true location of the + # Pulsar installation. + SCRIPT="$(readlink -f "$0")" + + # The `pulsar.sh` file lives one directory deeper than the root directory + # that contains the `pulsar` binary. + ATOM_APP="$(dirname "$(dirname "$SCRIPT")")" + PULSAR_PATH="$(realpath "$ATOM_APP")" - if [ "$ATOM_APP" == . ]; then + if [ ! -d "$PULSAR_PATH/pulsar" ]; then + # If that path doesn't contain a `pulsar` executable, then it's not a + # valid path. We'll try something else. unset ATOM_APP - else - PULSAR_PATH="$(dirname "$ATOM_APP")" + unset PULSAR_PATH fi if [ -z "${PULSAR_PATH}" ]; then @@ -207,7 +214,7 @@ elif [ $OS == 'Linux' ]; then fi fi - PULSAR_EXECUTABLE="$PULSAR_PATH/$ATOM_EXECUTABLE" + PULSAR_EXECUTABLE="$PULSAR_PATH/$ATOM_EXECUTABLE_NAME" PPM_EXECUTABLE="$(dirname "$PULSAR_PATH")/resources/app/ppm/bin/ppm" # If `-p` or `--package` was specified, call `ppm` with all the arguments From cbc815515a084e5ede195d8fdbf8e2ed70d19944 Mon Sep 17 00:00:00 2001 From: Andrew Dupont Date: Sat, 27 Jul 2024 15:54:44 -0700 Subject: [PATCH 4/7] CI experiment --- .github/workflows/package-tests-linux.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/package-tests-linux.yml b/.github/workflows/package-tests-linux.yml index db872336c4..f772228a0e 100644 --- a/.github/workflows/package-tests-linux.yml +++ b/.github/workflows/package-tests-linux.yml @@ -200,5 +200,5 @@ jobs: run: sudo apt-get install -y xvfb - name: Run ${{ matrix.package }} Tests - run: Xvfb :1 & cd node_modules/${{ matrix.package }} && if test -d spec; then DISPLAY=:1 pulsar --test spec; fi + run: export PULSAR_PATH="${TMPDIR:=/tmp}/pulsar-build/Pulsar"; Xvfb :1 & cd node_modules/${{ matrix.package }} && if test -d spec; then DISPLAY=:1 pulsar --test spec; fi # run: node -e "require('./script/run-package-tests')(/${{ matrix.package }}/)" From 71fab08ce3366d6d6e2297e8c15b57dfcdae2752 Mon Sep 17 00:00:00 2001 From: Andrew Dupont Date: Sat, 27 Jul 2024 16:06:33 -0700 Subject: [PATCH 5/7] Revert CI experiment; fix Linux detection --- .github/workflows/package-tests-linux.yml | 2 +- pulsar.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/package-tests-linux.yml b/.github/workflows/package-tests-linux.yml index f772228a0e..db872336c4 100644 --- a/.github/workflows/package-tests-linux.yml +++ b/.github/workflows/package-tests-linux.yml @@ -200,5 +200,5 @@ jobs: run: sudo apt-get install -y xvfb - name: Run ${{ matrix.package }} Tests - run: export PULSAR_PATH="${TMPDIR:=/tmp}/pulsar-build/Pulsar"; Xvfb :1 & cd node_modules/${{ matrix.package }} && if test -d spec; then DISPLAY=:1 pulsar --test spec; fi + run: Xvfb :1 & cd node_modules/${{ matrix.package }} && if test -d spec; then DISPLAY=:1 pulsar --test spec; fi # run: node -e "require('./script/run-package-tests')(/${{ matrix.package }}/)" diff --git a/pulsar.sh b/pulsar.sh index a1af505af1..154fc32c68 100755 --- a/pulsar.sh +++ b/pulsar.sh @@ -200,11 +200,11 @@ elif [ $OS == 'Linux' ]; then fi if [ -z "${PULSAR_PATH}" ]; then - if [ -d "/opt/Pulsar/pulsar" ]; then + if [ -f "/opt/Pulsar/pulsar" ]; then # Check the default installation directory for RPM and DEB # distributions. PULSAR_PATH="/opt/Pulsar" - elif [ -d "$TMPDIR/pulsar-build/Pulsar/pulsar" ]; then + elif [ -f "$TMPDIR/pulsar-build/Pulsar/pulsar" ]; then # This is where Pulsar can be found during some CI build tasks. PULSAR_PATH="$TMPDIR/pulsar-build/Pulsar" else From 00abb1cd25be0fd38cb2967acbed62c379bc3f82 Mon Sep 17 00:00:00 2001 From: Andrew Dupont Date: Sat, 27 Jul 2024 17:28:38 -0700 Subject: [PATCH 6/7] Further tweaks for generic Linux install --- pulsar.sh | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/pulsar.sh b/pulsar.sh index 154fc32c68..d5177010bf 100755 --- a/pulsar.sh +++ b/pulsar.sh @@ -167,12 +167,6 @@ if [ $OS == 'Mac' ]; then fi elif [ $OS == 'Linux' ]; then - if [ -L "$0" ]; then - SCRIPT="$(readlink -f "$0")" - else - SCRIPT="$0" - fi - # Set tmpdir only if it's unset. : ${TMPDIR:=/tmp} @@ -185,14 +179,18 @@ elif [ $OS == 'Linux' ]; then # of this script. When symlinked to a common location like # `/usr/local/bin`, this approach should find the true location of the # Pulsar installation. - SCRIPT="$(readlink -f "$0")" + if [ -L "$0" ]; then + SCRIPT="$(readlink -f "$0")" + else + SCRIPT="$0" + fi # The `pulsar.sh` file lives one directory deeper than the root directory # that contains the `pulsar` binary. ATOM_APP="$(dirname "$(dirname "$SCRIPT")")" PULSAR_PATH="$(realpath "$ATOM_APP")" - if [ ! -d "$PULSAR_PATH/pulsar" ]; then + if [ ! -f "$PULSAR_PATH/pulsar" ]; then # If that path doesn't contain a `pulsar` executable, then it's not a # valid path. We'll try something else. unset ATOM_APP From 66426dbb6e18d751cd32966befa000ea47e20f22 Mon Sep 17 00:00:00 2001 From: Andrew Dupont Date: Sat, 27 Jul 2024 17:43:13 -0700 Subject: [PATCH 7/7] Fix `ppm` argument handlling --- pulsar.sh | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/pulsar.sh b/pulsar.sh index d5177010bf..88d88717be 100755 --- a/pulsar.sh +++ b/pulsar.sh @@ -2,21 +2,6 @@ echoerr() { echo "$@" 1>&2; } -# Given a list of arguments, reduces them to the subset that follow the first -# occurrence of `-p` or `--package`. These are the arguments that will be -# passed to `ppm`. -shift_args_for_package_mode() { - loop_done=0 - while [ $loop_done -eq 0 ] - do - if [[ "$1" == "-p" || "$1" == "--package" || "$1" == "" ]]; then - # We'll shift one last time and then we'll be done. - loop_done=1 - fi - shift - done -} - if [ "$(uname)" == 'Darwin' ]; then OS='Mac' elif [ "$(expr substr $(uname -s) 1 5)" == 'Linux' ]; then @@ -26,7 +11,8 @@ else exit 1 fi -# Only set the ATOM_DISABLE_SHELLING_OUT_FOR_ENVIRONMENT env var if it hasn't been set. +# 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 @@ -93,6 +79,20 @@ fi ATOM_HOME="${ATOM_HOME:-$HOME/.pulsar}" mkdir -p "$ATOM_HOME" +if [ $PACKAGE_MODE ]; then + # If `-p` or `--package` is present, then we'll be discarding all arguments + # prior to (and including) `-p`/`--package` and passing the rest to `ppm`. + loop_done=0 + while [ $loop_done -eq 0 ] + do + if [[ "$1" == "-p" || "$1" == "--package" || "$1" == "" ]]; then + # We'll shift one last time and then we'll be done. + loop_done=1 + fi + shift + done +fi + if [ $OS == 'Mac' ]; then if [ -L "$0" ]; then SCRIPT="$(readlink "$0")" @@ -149,7 +149,6 @@ if [ $OS == 'Mac' ]; then # If `-p` or `--package` was specified, call `ppm` with all the arguments # that followed it instead of calling the Pulsar executable directly. if [ $PACKAGE_MODE ]; then - shift_args_for_package_mode "$PPM_EXECUTABLE" "$@" exit $? fi @@ -213,12 +212,11 @@ elif [ $OS == 'Linux' ]; then fi PULSAR_EXECUTABLE="$PULSAR_PATH/$ATOM_EXECUTABLE_NAME" - PPM_EXECUTABLE="$(dirname "$PULSAR_PATH")/resources/app/ppm/bin/ppm" + PPM_EXECUTABLE="$PULSAR_PATH/resources/app/ppm/bin/ppm" # If `-p` or `--package` was specified, call `ppm` with all the arguments # that followed it instead of calling the Pulsar executable directly. if [ $PACKAGE_MODE ]; then - shift_args_for_package_mode "$PPM_EXECUTABLE" "$@" exit $? fi