Last active
April 28, 2020 13:31
-
-
Save homostellaris/fd003adee7eb964dc1ffbe05503a38b5 to your computer and use it in GitHub Desktop.
habitat.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Loads environment variables from a dot env (.env) file before calling the specified command. | |
# Parse -f and assign it to $OPTARG. Also assigns 'f' to $opt but that is not needed. | |
getopts f: opt | |
# If a path has been provided for the dot env file use that otherwise look in the working directory. | |
DOT_ENV_FILE_PATH=${OPTARG:-./.env} | |
# Shift option parameters away so that $1 becomes the command to run rather than '-f'. | |
shift $((OPTIND-1)) | |
# Set the shell to export all variables set from this point onwards. | |
set -a | |
# If running Jest it will lose its colored output unless we set this. | |
FORCE_COLOR=true | |
# Load the dot env file. | |
. $DOT_ENV_FILE_PATH | |
# Execute the command. | |
exec $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment