direnv.plugin.zsh 609 B

12345678910111213141516171819
  1. # If direnv is not found, don't continue and print a warning
  2. if (( ! $+commands[direnv] )); then
  3. echo "Warning: direnv not found. Please install direnv and ensure it's in your PATH before using this plugin."
  4. return
  5. fi
  6. _direnv_hook() {
  7. trap -- '' SIGINT;
  8. eval "$(direnv export zsh)";
  9. trap - SIGINT;
  10. }
  11. typeset -ag precmd_functions;
  12. if [[ -z "${precmd_functions[(r)_direnv_hook]+1}" ]]; then
  13. precmd_functions=( _direnv_hook ${precmd_functions[@]} )
  14. fi
  15. typeset -ag chpwd_functions;
  16. if [[ -z "${chpwd_functions[(r)_direnv_hook]+1}" ]]; then
  17. chpwd_functions=( _direnv_hook ${chpwd_functions[@]} )
  18. fi