summaryrefslogtreecommitdiff
path: root/plugins/dotenv
diff options
context:
space:
mode:
authorArshad Kazmi <arshadkazmi42@gmail.com>2019-05-20 02:15:27 +0530
committerMarc Cornellà <marc.cornella@live.com>2019-05-19 22:45:27 +0200
commitf960e2be6f01abe5f185d668be661b57051322ac (patch)
tree7453488d95706cc16328834e0a5b8a94abbb6a92 /plugins/dotenv
parent5f7666e20b411ac4b71844d72945f9e122909dbc (diff)
downloadzsh-f960e2be6f01abe5f185d668be661b57051322ac.tar.gz
zsh-f960e2be6f01abe5f185d668be661b57051322ac.tar.bz2
zsh-f960e2be6f01abe5f185d668be661b57051322ac.zip
dotenv: add support for custom env file names (#7861)
Diffstat (limited to 'plugins/dotenv')
-rw-r--r--plugins/dotenv/README.md11
-rw-r--r--plugins/dotenv/dotenv.plugin.zsh12
2 files changed, 19 insertions, 4 deletions
diff --git a/plugins/dotenv/README.md b/plugins/dotenv/README.md
index e880e9d69..cac552485 100644
--- a/plugins/dotenv/README.md
+++ b/plugins/dotenv/README.md
@@ -32,6 +32,17 @@ PORT=3001
```
You can even mix both formats, although it's probably a bad idea.
+### ZSH_DOTENV_FILE
+
+You can also modify the name of the file to be loaded with the variable `ZSH_DOTENV_FILE`.
+If the variable isn't set, the plugin will default to use `.env`.
+For example, this will make the plugin look for files named `.dotenv` and load them:
+
+```
+# in ~/.zshrc, before Oh My Zsh is sourced:
+ZSH_DOTENV_FILE=.dotenv
+```
+
## Version Control
**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's supposed to be local only.
diff --git a/plugins/dotenv/dotenv.plugin.zsh b/plugins/dotenv/dotenv.plugin.zsh
index b701b5596..89763d0ee 100644
--- a/plugins/dotenv/dotenv.plugin.zsh
+++ b/plugins/dotenv/dotenv.plugin.zsh
@@ -1,13 +1,13 @@
source_env() {
- if [[ -f .env ]]; then
+ if [[ -f $ZSH_DOTENV_FILE ]]; then
# test .env syntax
- zsh -fn .env || echo 'dotenv: error when sourcing `.env` file' >&2
+ zsh -fn $ZSH_DOTENV_FILE || echo "dotenv: error when sourcing '$ZSH_DOTENV_FILE' file" >&2
if [[ -o a ]]; then
- source .env
+ source $ZSH_DOTENV_FILE
else
set -a
- source .env
+ source $ZSH_DOTENV_FILE
set +a
fi
fi
@@ -16,4 +16,8 @@ source_env() {
autoload -U add-zsh-hook
add-zsh-hook chpwd source_env
+if [[ -z $ZSH_DOTENV_FILE ]]; then
+ ZSH_DOTENV_FILE=.env
+fi
+
source_env