diff options
Diffstat (limited to 'plugins/dotenv/dotenv.plugin.zsh')
-rw-r--r-- | plugins/dotenv/dotenv.plugin.zsh | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/plugins/dotenv/dotenv.plugin.zsh b/plugins/dotenv/dotenv.plugin.zsh new file mode 100644 index 000000000..b701b5596 --- /dev/null +++ b/plugins/dotenv/dotenv.plugin.zsh @@ -0,0 +1,19 @@ +source_env() { + if [[ -f .env ]]; then + # test .env syntax + zsh -fn .env || echo 'dotenv: error when sourcing `.env` file' >&2 + + if [[ -o a ]]; then + source .env + else + set -a + source .env + set +a + fi + fi +} + +autoload -U add-zsh-hook +add-zsh-hook chpwd source_env + +source_env |