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              eval (direnv hook fish)
84
85
86
87   TCSH
88       Add the following line at the end of the  /.cshrc file:
89
90
91              eval `direnv hook tcsh`
92
93
94
95   Elvish
96       Run:
97
98
99              $> direnv hook elvish >  /.elvish/lib/direnv.elv
100
101
102
103       and add the following line to your  /.elvish/rc.elv file:
104
105
106              use direnv
107
108
109

USAGE

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

CONTRIBUTE

146       Bug reports, contributions and forks are welcome.
147
148
149       All bugs or other forms of discussion happen on
150
151http://github.com/direnv/direnv/issues
152
153
154       There is also a wiki available where you can share your usage  patterns
155       or other tips and tricks ⟨https://github.com/direnv/direnv/wiki
156
157
158       Or  drop by on the #direnv channel on FreeNode ⟨irc://#direnv@FreeNode⟩
159       to have a chat.
160
161
163       MIT licence - Copyright (C) 2019 @zimbatm and contributors
164
165

SEE ALSO

167       direnv-stdlib(1), direnv.toml(1)
168
169
170
171direnv                               2019                            DIRENV(1)
Impressum