1DIRENV(1)                        User Manuals                        DIRENV(1)
2
3
4

NAME

6       direnv - unclutter your .profile
7
8

SYNOPSIS

10       direnv command ...
11
12

DESCRIPTION

14       direnv  is an environment variable manager for your shell. It knows how
15       to hook into bash, zsh and fish shell to  load  or  unload  environment
16       variables  depending on your current directory. This allows you to have
17       project-specific environment variables and not clutter the " /.profile"
18       file.
19
20
21       Before each prompt it checks for the existence of an .envrc file in the
22       current and parent directories. If the file exists, it is loaded into a
23       bash  sub-shell  and all exported variables are then captured by direnv
24       and then made available to your current shell,  while  unset  variables
25       are removed.
26
27
28       Because  direnv  is compiled into a single static executable it is fast
29       enough to be unnoticeable on each prompt. It is also language  agnostic
30       and can be used to build solutions similar to rbenv, pyenv, phpenv, ...
31
32

EXAMPLE

34              $ cd  /my_project
35              $ echo ${FOO-nope}
36              nope
37              $ echo export FOO=foo > .envrc
38              \.envrc is not allowed
39              $ direnv allow .
40              direnv: reloading
41              direnv: loading .envrc
42              direnv export: +FOO
43              $ echo ${FOO-nope}
44              foo
45              $ cd ..
46              direnv: unloading
47              direnv export:  PATH
48              $ echo ${FOO-nope}
49              nope
50
51
52

SETUP

54       For  direnv to work properly it needs to be hooked into the shell. Each
55       shell has it's own extension mechanism:
56
57
58   BASH
59       Add the following line at the end of the  /.bashrc file:
60
61
62              eval "$(direnv hook bash)"
63
64
65
66       Make sure it appears even after rvm, git-prompt and other shell  exten‐
67       sions that manipulate the prompt.
68
69
70   ZSH
71       Add the following line at the end of the  /.zshrc file:
72
73
74              eval "$(direnv hook zsh)"
75
76
77
78   FISH
79       Add  the  following  line  at the end of the  /.config/fish/config.fish
80       file:
81
82
83              direnv hook fish | source
84
85
86
87       Fish supports 3 modes you can set  with  with  the  global  environment
88       variable direnv_fish_mode:
89
90
91              set -g direnv_fish_mode eval_on_arrow    # trigger direnv at prompt, and on every arrow-based directory change (default)
92              set -g direnv_fish_mode eval_after_arrow # trigger direnv at prompt, and only after arrow-based directory changes before executing command
93              set -g direnv_fish_mode disable_arrow    # trigger direnv at prompt only, this is similar functionality to the original behavior
94
95
96
97   TCSH
98       Add the following line at the end of the  /.cshrc file:
99
100
101              eval `direnv hook tcsh`
102
103
104
105   Elvish
106       Run:
107
108
109              $> direnv hook elvish >  /.elvish/lib/direnv.elv
110
111
112
113       and add the following line to your  /.elvish/rc.elv file:
114
115
116              use direnv
117
118
119

USAGE

121       In some target folder, create an .envrc file and add some export(1) and
122       unset(1) directives in it.
123
124
125       On the next prompt you will notice  that  direnv  complains  about  the
126       .envrc  being  blocked. This is the security mechanism to avoid loading
127       new files automatically. Otherwise any git repo that you pull,  or  tar
128       archive that you unpack, would be able to wipe your hard drive once you
129       cd into it.
130
131
132       So here we are pretty sure that it won't do anything bad.  Type  direnv
133       allow  .   and  watch  direnv  loading  your new environment. Note that
134       direnv edit . is a handy shortcut that opens the file in  your  $EDITOR
135       and  automatically  reloads  it  if  the  file's  modification time has
136       changed.
137
138
139       Now that the environment is loaded you can notice that once you cd  out
140       of the directory it automatically gets unloaded. If you cd back into it
141       it's loaded again. That's the base of the mechanism that allows you  to
142       build cool things.
143
144
145       Exporting  variables  by  hand is a bit repetitive so direnv provides a
146       set of utility functions that are made available in the context of  the
147       .envrc file.  Check the direnv-stdlib(1) man page for more details. You
148       can also define your own extensions inside  /.config/direnv/direnvrc or
149       /.config/direnv/lib/*.sh files.
150
151
152       Hopefully this is enough to get you started.
153
154

CONTRIBUTE

156       Bug reports, contributions and forks are welcome.
157
158
159       All bugs or other forms of discussion happen on
160
161http://github.com/direnv/direnv/issues
162
163
164       There  is also a wiki available where you can share your usage patterns
165       or other tips and tricks ⟨https://github.com/direnv/direnv/wiki
166
167
168       Or drop by on the #direnv channel on FreeNode  ⟨irc://#direnv@FreeNode⟩
169       to have a chat.
170
171
173       MIT licence - Copyright (C) 2019 @zimbatm and contributors
174
175

SEE ALSO

177       direnv-stdlib(1), direnv.toml(1), direnv-fetchurl(1)
178
179
180
181direnv                               2019                            DIRENV(1)
Impressum