direnv.plugin.zsh
609 bytes
1# If direnv is not found, don't continue and print a warning
2if (( ! $+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
5fi
6
7_direnv_hook() {
8 trap -- '' SIGINT;
9 eval "$(direnv export zsh)";
10 trap - SIGINT;
11}
12typeset -ag precmd_functions;
13if [[ -z "${precmd_functions[(r)_direnv_hook]+1}" ]]; then
14 precmd_functions=( _direnv_hook ${precmd_functions[@]} )
15fi
16typeset -ag chpwd_functions;
17if [[ -z "${chpwd_functions[(r)_direnv_hook]+1}" ]]; then
18 chpwd_functions=( _direnv_hook ${chpwd_functions[@]} )
19fi