diff options
author | Arthur <mardybm@gmail.com> | 2016-12-14 22:49:08 +0600 |
---|---|---|
committer | Marc CornellĂ <marc.cornella@live.com> | 2016-12-14 17:49:08 +0100 |
commit | 8d35fa0e2f32dab6894ca06bfc333af94be97ec7 (patch) | |
tree | 23bb7c1d29dcaf8af395957d3e4378618f50f658 /plugins/dotenv | |
parent | 3b13dc07d823ebcb67ea429de305b5413e99ac1e (diff) | |
download | zsh-8d35fa0e2f32dab6894ca06bfc333af94be97ec7.tar.gz zsh-8d35fa0e2f32dab6894ca06bfc333af94be97ec7.tar.bz2 zsh-8d35fa0e2f32dab6894ca06bfc333af94be97ec7.zip |
add dotenv plugin (#4373)
Diffstat (limited to 'plugins/dotenv')
-rw-r--r-- | plugins/dotenv/README.md | 34 | ||||
-rw-r--r-- | plugins/dotenv/dotenv.plugin.zsh | 10 |
2 files changed, 44 insertions, 0 deletions
diff --git a/plugins/dotenv/README.md b/plugins/dotenv/README.md new file mode 100644 index 000000000..ade09fbb2 --- /dev/null +++ b/plugins/dotenv/README.md @@ -0,0 +1,34 @@ +# 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](http://www.12factor.net). Anything that is likely to change between deployment environments–such as resource handles for databases or credentials for external services–should be extracted from the code into environment variables. + +## Installation + +Just add the plugin to your `.zshrc`: + +```sh +plugins=(git man dotenv) +``` + +## Usage + +Create `.env` file inside your project directory and put your local ENV variables there. + +For example: +```sh +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: +```sh +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. diff --git a/plugins/dotenv/dotenv.plugin.zsh b/plugins/dotenv/dotenv.plugin.zsh new file mode 100644 index 000000000..9dd784229 --- /dev/null +++ b/plugins/dotenv/dotenv.plugin.zsh @@ -0,0 +1,10 @@ +#!/bin/zsh + +source_env() { + if [[ -f .env ]]; then + source .env + fi +} + +autoload -U add-zsh-hook +add-zsh-hook chpwd source_env |