6dee9f99d3fc74fbbf560fb8957c180d71da7c99

Author
Moritz Schwörer <mr.mosch@gmail.com>
Committer
GitHub <noreply@github.com>
Date

Message

Add direnv plugin (#8666)

Diff

 1diff --git a/plugins/direnv/README.md b/plugins/direnv/README.md
 2new file mode 100644
 3index 0000000000000000000000000000000000000000..8deaf38bb5da2e7e1733ab30137e64cf03cf3182
 4--- /dev/null
 5+++ b/plugins/direnv/README.md
 6@@ -0,0 +1,15 @@
 7+# direnv plugin
 8+
 9+This plugin creates the [Direnv](https://direnv.net/) hook.
10+
11+To use it, add `direnv` to the plugins array in your zshrc file:
12+
13+```zsh
14+plugins=(... direnv)
15+```
16+
17+## Requirements
18+
19+In order to make this work, you will need to have the direnv installed.
20+
21+More info on the usage and install: https://github.com/direnv/direnv
22diff --git a/plugins/direnv/direnv.plugin.zsh b/plugins/direnv/direnv.plugin.zsh
23new file mode 100644
24index 0000000000000000000000000000000000000000..204f46d72ddfe017b6f83973fcd9bd5b2066b5b7
25--- /dev/null
26+++ b/plugins/direnv/direnv.plugin.zsh
27@@ -0,0 +1,13 @@
28+_direnv_hook() {
29+  trap -- '' SIGINT;
30+  eval "$("/usr/local/bin/direnv" export zsh)";
31+  trap - SIGINT;
32+}
33+typeset -ag precmd_functions;
34+if [[ -z ${precmd_functions[(r)_direnv_hook]} ]]; then
35+  precmd_functions=( _direnv_hook ${precmd_functions[@]} )
36+fi
37+typeset -ag chpwd_functions;
38+if [[ -z ${chpwd_functions[(r)_direnv_hook]} ]]; then
39+  chpwd_functions=( _direnv_hook ${chpwd_functions[@]} )
40+fi