2016-12-14 17:49:08 +01:00
|
|
|
source_env() {
|
2019-05-19 22:45:27 +02:00
|
|
|
if [[ -f $ZSH_DOTENV_FILE ]]; then
|
2020-02-13 18:10:59 +01:00
|
|
|
if [ "$ZSH_DOTENV_PROMPT" != "false" ]; then
|
|
|
|
# confirm before sourcing file
|
|
|
|
local confirmation
|
2020-02-13 18:33:24 +01:00
|
|
|
# print same-line prompt and output newline character if necessary
|
2020-02-13 18:10:59 +01:00
|
|
|
echo -n "dotenv: source '$ZSH_DOTENV_FILE' file in the directory? (Y/n) "
|
2020-02-13 18:33:24 +01:00
|
|
|
read -k 1 confirmation; [[ "$confirmation" != $'\n' ]] && echo
|
|
|
|
# only bail out if confirmation character is n
|
|
|
|
if [[ "$confirmation" = [nN] ]]; then
|
2020-02-13 18:10:59 +01:00
|
|
|
return
|
|
|
|
fi
|
2020-02-12 17:51:40 +01:00
|
|
|
fi
|
|
|
|
|
2018-08-08 00:05:34 +02:00
|
|
|
# test .env syntax
|
2019-05-19 22:45:27 +02:00
|
|
|
zsh -fn $ZSH_DOTENV_FILE || echo "dotenv: error when sourcing '$ZSH_DOTENV_FILE' file" >&2
|
2018-08-08 00:05:34 +02:00
|
|
|
|
2018-07-10 23:31:47 +02:00
|
|
|
if [[ -o a ]]; then
|
2019-05-19 22:45:27 +02:00
|
|
|
source $ZSH_DOTENV_FILE
|
2018-07-10 23:31:47 +02:00
|
|
|
else
|
|
|
|
set -a
|
2019-05-19 22:45:27 +02:00
|
|
|
source $ZSH_DOTENV_FILE
|
2018-07-10 23:31:47 +02:00
|
|
|
set +a
|
|
|
|
fi
|
2016-12-14 17:49:08 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
autoload -U add-zsh-hook
|
|
|
|
add-zsh-hook chpwd source_env
|
2018-08-07 23:54:07 +02:00
|
|
|
|
2019-05-19 22:45:27 +02:00
|
|
|
if [[ -z $ZSH_DOTENV_FILE ]]; then
|
|
|
|
ZSH_DOTENV_FILE=.env
|
|
|
|
fi
|
|
|
|
|
2018-08-07 23:54:07 +02:00
|
|
|
source_env
|