ohmyzsh/plugins/dotenv
Mahmoud Zalt 91b09eb848 Add a message informing users about parsing errors
I couldn't tell why I got this error `.env: line 129: syntax error near unexpected token `('` after adding a bunch of plugins.
I didn't knew what most of the plugins do, nor what the `dotenv` plugin is doing behind the scene!
After figuring out the problem, I though it would be much better displaying an error message only in case there are some parsing errors. Now I would get this:

```
Found some errors while parsing your .env file:
.env: line 129: syntax error near unexpected token `('
```
2017-10-06 07:25:01 +03:00
..
dotenv.plugin.zsh Add a message informing users about parsing errors 2017-10-06 07:25:01 +03:00
README.md add dotenv plugin (#4373) 2016-12-14 17:49:08 +01:00

dotenv

Automatically load your project ENV variables from .env file when you cd into project root directory.

Storing configuration in the environment is one of the tenets of a twelve-factor app. Anything that is likely to change between deployment environmentssuch as resource handles for databases or credentials for external servicesshould be extracted from the code into environment variables.

Installation

Just add the plugin to your .zshrc:

plugins=(git man dotenv)

Usage

Create .env file inside your project directory and put your local ENV variables there.

For example:

export AWS_S3_TOKEN=d84a83539134f28f412c652b09f9f98eff96c9a
export SECRET_KEY=7c6c72d959416d5aa368a409362ec6e2ac90d7f
export MONGO_URI=mongodb://127.0.0.1:27017
export PORT=3001

export is optional. This format works as well:

AWS_S3_TOKEN=d84a83539134f28f412c652b09f9f98eff96c9a
SECRET_KEY=7c6c72d959416d5aa368a409362ec6e2ac90d7f
MONGO_URI=mongodb://127.0.0.1:27017
PORT=3001

It's strongly recommended to add .env file to .gitignore, because usually it contains sensitive information such as your credentials, secret keys, passwords etc. You don't want to commit this file, it supposed to be local only.