2016-12-15 00:49:08 +08:00
|
|
|
source_env() {
|
2019-05-20 04:45:27 +08:00
|
|
|
if [[ -f $ZSH_DOTENV_FILE ]]; then
|
2020-02-14 01:10:59 +08:00
|
|
|
|
|
|
|
if [ "$ZSH_DOTENV_PROMPT" != "false" ]; then
|
|
|
|
# confirm before sourcing file
|
|
|
|
local confirmation
|
|
|
|
echo -n "dotenv: source '$ZSH_DOTENV_FILE' file in the directory? (Y/n) "
|
|
|
|
if read -k 1 confirmation && [[ $confirmation = [nN] ]]; then
|
|
|
|
return
|
|
|
|
fi
|
2020-02-13 00:51:40 +08:00
|
|
|
fi
|
|
|
|
|
2018-08-08 06:05:34 +08:00
|
|
|
# test .env syntax
|
2019-05-20 04:45:27 +08:00
|
|
|
zsh -fn $ZSH_DOTENV_FILE || echo "dotenv: error when sourcing '$ZSH_DOTENV_FILE' file" >&2
|
2018-08-08 06:05:34 +08:00
|
|
|
|
2018-07-11 05:31:47 +08:00
|
|
|
if [[ -o a ]]; then
|
2019-05-20 04:45:27 +08:00
|
|
|
source $ZSH_DOTENV_FILE
|
2018-07-11 05:31:47 +08:00
|
|
|
else
|
|
|
|
set -a
|
2019-05-20 04:45:27 +08:00
|
|
|
source $ZSH_DOTENV_FILE
|
2018-07-11 05:31:47 +08:00
|
|
|
set +a
|
|
|
|
fi
|
2016-12-15 00:49:08 +08:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
autoload -U add-zsh-hook
|
|
|
|
add-zsh-hook chpwd source_env
|
2018-08-08 05:54:07 +08:00
|
|
|
|
2019-05-20 04:45:27 +08:00
|
|
|
if [[ -z $ZSH_DOTENV_FILE ]]; then
|
|
|
|
ZSH_DOTENV_FILE=.env
|
|
|
|
fi
|
|
|
|
|
2018-08-08 05:54:07 +08:00
|
|
|
source_env
|