Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotenv plugin: agree once improvement #8729

Merged
merged 8 commits into from
Mar 23, 2020
Prev Previous commit
Next Next commit
Simplify and reorder file; change default allowed list path
  • Loading branch information
mcornella committed Mar 22, 2020
commit 29fff53992a008cc769661b08f4722bc2565e615
28 changes: 13 additions & 15 deletions plugins/dotenv/dotenv.plugin.zsh
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## Settings

# Filename of the dotenv file to look for
: ${ZSH_DOTENV_FILE:=.env}

# Path to the file containing allowed paths
: ${ZSH_DOTENV_ALLOWED_LIST:="${ZSH_CACHE_DIR}/dotenv-allowed.list"}


## Functions

source_env() {
if [[ -f $ZSH_DOTENV_FILE ]]; then
if [[ "$ZSH_DOTENV_PROMPT" != false ]]; then
Expand All @@ -24,25 +35,12 @@ source_env() {
# test .env syntax
zsh -fn $ZSH_DOTENV_FILE || echo "dotenv: error when sourcing '$ZSH_DOTENV_FILE' file" >&2

if [[ -o a ]]; then
source $ZSH_DOTENV_FILE
else
set -a
source $ZSH_DOTENV_FILE
set +a
fi
setopt localoptions allexport
source $ZSH_DOTENV_FILE
fi
}

autoload -U add-zsh-hook
add-zsh-hook chpwd source_env

if [[ -z $ZSH_DOTENV_FILE ]]; then
ZSH_DOTENV_FILE=.env
fi

if [[ -z $ZSH_DOTENV_AGREE_LIST_FILE ]]; then
ZSH_DOTENV_AGREE_LIST_FILE="${ZSH}/dotenv-agree.list"
fi

source_env