#!/bin/bash

# set -e # Will close terminal if used in profile/.bashrc, etc

SCRIPT_PATH="$(readlink -f "${BASH_SOURCE[0]}")"
SCRIPT_DIR="$(dirname "$SCRIPT_PATH")"

if [[ -f "$SCRIPT_DIR/activate" ]]; then
    . "$SCRIPT_DIR/activate"
else
    export PATH="${SCRIPT_DIR}:${PATH}"
fi

. parse-args "$@"

#echo "Original string: $@. ARGS: ${ARGS[*]} and ALL is $ALL"

if [[ "$ALL" == "1" ]]; then
    unset ALL # Prevents ALL being propagated to any child calls of self.
    for item in "${ARGS[@]}"; do
      echo "Running script: $item"
      "$item"
    done
else
    exec "$@"
fi