dotenv.plugin.zsh 436 Bytes
Newer Older
Arthur's avatar
Arthur committed
1
source_env() {
2
  if [[ -f $ZSH_DOTENV_FILE ]]; then
3
    # test .env syntax
4
    zsh -fn $ZSH_DOTENV_FILE || echo "dotenv: error when sourcing '$ZSH_DOTENV_FILE' file" >&2
5

6
    if [[ -o a ]]; then
7
      source $ZSH_DOTENV_FILE
8
9
    else
      set -a
10
      source $ZSH_DOTENV_FILE
11
12
      set +a
    fi
Arthur's avatar
Arthur committed
13
14
15
16
17
  fi
}

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

19
20
21
22
if [[ -z $ZSH_DOTENV_FILE ]]; then
    ZSH_DOTENV_FILE=.env
fi

23
source_env