dotenv.plugin.zsh 436 B

1234567891011121314151617181920212223
  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. if [[ -o a ]]; then
  6. source $ZSH_DOTENV_FILE
  7. else
  8. set -a
  9. source $ZSH_DOTENV_FILE
  10. set +a
  11. fi
  12. fi
  13. }
  14. autoload -U add-zsh-hook
  15. add-zsh-hook chpwd source_env
  16. if [[ -z $ZSH_DOTENV_FILE ]]; then
  17. ZSH_DOTENV_FILE=.env
  18. fi
  19. source_env