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
22       the current and parent directories. If the file exists,  it  is  loaded
23       into  a  bash sub-shell and all exported variables are then captured by
24       direnv and then made available to your current shell.
25
26
27       Because direnv is compiled into a single static executable it  is  fast
28       enough  to be unnoticeable on each prompt. It is also language agnostic
29       and can be used to build solutions similar to rbenv, pyenv, phpenv, ...
30
31

EXAMPLE

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

SETUP

52       For direnv to work properly it needs to be hooked into the shell.  Each
53       shell has it's own extension mechanism:
54
55
56   BASH
57       Add the following line at the end of your " /.bashrc" file:
58
59
60       eval "$(direnv hook bash)"
61
62
63       Make  sure it appears even after rvm, git-prompt and other shell exten‐
64       sions that manipulate your prompt.
65
66
67   ZSH
68       Add the following line at the end of your " /.zshrc" file:
69
70
71       eval "$(direnv hook zsh)"
72
73
74   FISH
75       Add the following line at the end of your "  /.config/fish/config.fish"
76       file:
77
78
79       eval (direnv hook fish)
80
81
82   TCSH
83       Add the following line at the end of your " /.cshrc" file:
84
85
86              eval `direnv hook tcsh`
87
88
89

USAGE

91       In  some  target folder, create an ".envrc" file and add some export(1)
92       directives in it.
93
94
95       On the next prompt you will notice  that  direnv  complains  about  the
96       ".envrc" being blocked. This is the security mechanism to avoid loading
97       new files automatically. Otherwise any git repo that you pull,  or  tar
98       archive that you unpack, would be able to wipe your hard drive once you
99       cd into it.
100
101
102       So here we are pretty sure that it won't do anything bad.  Type  direnv
103       allow  .   and  watch  direnv  loading  your new environment. Note that
104       direnv edit . is a handy shortcut that open the file  in  your  $EDITOR
105       and  automatically  allows  it  if  the  file's  modification  time has
106       changed.
107
108
109       Now that the environment is loaded you can notice that once you cd  out
110       of the directory it automatically gets unloaded. If you cd back into it
111       it's loaded again. That's the base of the mechanism that allows you  to
112       build cool things.
113
114
115       Exporting  variables  by  hand is a bit repetitive so direnv provides a
116       set of utility functions that are made available in the context of  the
117       ".envrc"  file.   Check the direnv-stdlib(1) man page for more details.
118       You can also define your own extensions inside a " /.direnvrc" file.
119
120
121       Hopefully this is enough to get you started.
122
123

CONTRIBUTE

125       Bug reports, contributions and forks are welcome.
126
127
128       All bugs or other forms of discussion happen on
129
130http://github.com/direnv/direnv/issues
131
132
133       There is also a wiki available where you can share your usage  patterns
134       or other tips and tricks ⟨https://github.com/direnv/direnv/wiki
135
136
137       Or drop by on the ⟨irc://#direnv@FreeNode⟩ to have a chat.
138
139
141       Copyright (C) 2014 zimbatm and contributors under the MIT licence.
142
143

SEE ALSO

145       direnv-stdlib(1)
146
147
148
149direnv                            APRIL 2014                         DIRENV(1)
Impressum