1DIRENV-STDLIB(1) User Manuals DIRENV-STDLIB(1)
2
3
4
6 direnv_stdlib - the ".envrc" stdlib
7
8
10 direnv stdlib
11
12
14 Outputs a bash script called the stdlib. The following commands are
15 included in that script and loaded in the context of an ".envrc". In
16 addition, it also loads the file in " /.direnvrc" if it exists.
17
18
20 has command: Returns 0 if the command is available. Returns 1 other‐
21 wise. It can be a binary in the PATH or a shell function.
22
23
24 Example:
25
26
27 if has curl; then
28 echo "Yes we do"
29 fi
30
31
32 · expand_path rel_path [relative_to]: Outputs the absolute path of
33 rel_path relative to relative_to or the current directory.
34
35
36 Example:
37
38
39 cd /usr/local/games
40 expand_path ../foo
41 # output: /usr/local/foo
42
43
44 ·
45
46
47 dotenv [dotenv_path]: Loads a ".env" file into the current environment
48
49 ·
50
51
52 user_rel_path abs_path: Transforms an absolute path abs_path into a
53 user-relative path if possible.
54
55
56 Example:
57
58
59 echo $HOME
60 # output: /home/user
61 user_rel_path /home/user/my/project
62 # output: /my/project
63 user_rel_path /usr/local/lib
64 # output: /usr/local/lib
65
66
67 · find_up filename: Outputs the path of filename when searched from the
68 current directory up to /. Returns 1 if the file has not been found.
69
70
71 Example:
72
73
74 cd /usr/local/my
75 mkdir -p project/foo
76 touch bar
77 cd project/foo
78 find_up bar
79 # output: /usr/local/my/bar
80
81
82 ·
83
84
85 source_env file_or_dir_path: Loads another ".envrc" either by specify‐
86 ing its path or filename.
87
88 NOTE: the other ".envrc" is not checked by the security framework.
89
90 ·
91
92
93 source_up [filename]: Loads another ".envrc" if found with the find_up
94 command.
95
96 NOTE: the other ".envrc" is not checked by the security framework.
97
98 ·
99
100
101 direnv_load [command-generating-dump-output] Applies the environment
102 generated by running argv as a command. This is useful for adopting the
103 environment of a child process - cause that process to run "direnv
104 dump" and then wrap the results with direnv_load.
105
106
107 Example:
108
109
110 direnv_load opam-env exec -- direnv dump
111
112
113 · PATH_add path: Prepends the expanded path to the PATH environment
114 variable. It prevents a common mistake where PATH is replaced by only
115 the new path.
116
117
118 Example:
119
120
121 pwd
122 # output: /home/user/my/project
123 PATH_add bin
124 echo $PATH
125 # output: /home/user/my/project/bin:/usr/bin:/bin
126
127
128 ·
129
130
131 MANPATH_add path: Prepends the expanded path to the MANPATH environment
132 variable. It takes care of man-specific heuritic.
133
134 ·
135
136
137 path_add varname path: Works like PATH_add except that it's for an
138 arbitrary varname.
139
140 ·
141
142
143 load_prefix prefix_path: Expands some common path variables for the
144 given prefix_path prefix. This is useful if you installed something in
145 the prefix_path using ./configure --prefix=$prefix_path make install
146 and want to use it in the project.
147
148
149 Variables set:
150
151
152 CPATH
153 LD_LIBRARY_PATH
154 LIBRARY_PATH
155 MANPATH
156 PATH
157 PKG_CONFIG_PATH
158
159
160
161 Example:
162
163
164 ./configure --prefix=$HOME/rubies/ruby-1.9.3
165 make make install
166 # Then in the .envrc
167 load_prefix /rubies/ruby-1.9.3
168
169
170 ·
171
172
173 layout type: A semantic dispatch used to describe common project lay‐
174 outs.
175
176 ·
177
178
179 layout go: Sets the GOPATH environment variable to the current direc‐
180 tory.
181
182 ·
183
184
185 layout node: Adds "$PWD/node_modules/.bin" to the PATH environment
186 variable.
187
188 ·
189
190
191 layout perl: Setup environment variables required by perl's local::lib
192 See ⟨http://search.cpan.org/dist/local-lib/lib/local/lib.pm⟩ for more
193 details
194
195 ·
196
197
198 layout python [python_exe]: Creates and loads a virtualenv environment
199 under $PWD/.direnv/python-$python_version. This forces the installation
200 of any egg into the project's sub-folder.
201
202 It's possible to specify the python executable if you want to use dif‐
203 ferent versions of python (eg: layout python python3).
204
205
206 Note that previously virtualenv was located under $PWD/.direnv/vir‐
207 tualenv and will be re-used by direnv if it exists.
208
209 ·
210
211
212 layout python3: A shortcut for layout python python3
213
214 ·
215
216
217 layout ruby: Sets the GEM_HOME environment variable to
218 $PWD/.direnv/ruby/RUBY_VERSION. This forces the installation of any
219 gems into the project's sub-folder. If you're using bundler it will
220 create wrapper programs that can be invoked directly instead of using
221 the bundle exec prefix.
222
223 ·
224
225
226 use program_name [version]: A semantic command dispatch intended for
227 loading external dependencies into the environment.
228
229
230 Example:
231
232
233 use_ruby() {
234 echo "Ruby $1"
235 }
236 use ruby 1.9.3
237 # output: Ruby 1.9.3
238
239
240 · use rbenv: Loads rbenv which add the ruby wrappers available on the
241 PATH.
242
243 ·
244
245
246 use nix [...]: Load environment variables from nix-shell.
247
248 If you have a default.nix or shell.nix these will be used by default,
249 but you can also specify packages directly (e.g use nix -p ocaml).
250
251
252 See ⟨http://nixos.org/nix/manual/#sec-nix-shell⟩
253
254 ·
255
256
257 use guix [...]: Load environment variables from guix environment.
258
259 Any arguments given will be passed to guix environment. For example,
260 use guix hello would setup an environment with the dependencies of the
261 hello package. To create an environment including hello, the --ad-hoc
262 flag is used use guix --ad-hoc hello. Other options include --load
263 which allows loading an environment from a file.
264
265
266 See ⟨https://www.gnu.org/software/guix/manual/html_node/Invoking-guix-
267 environment.html⟩
268
269 ·
270
271
272 rvm ...: Should work just like in the shell if you have rvm installed.
273
274 ·
275
276
277 use node: Loads NodeJS version from a .node-version or .nvmrc file.
278
279 If you specify a partial NodeJS version (i.e. 4.2), a fuzzy match is
280 performed and the highest matching version installed is selected.
281
282
283 Example (.envrc):
284
285
286 set -e
287 use node
288
289
290
291 Example (.node-version):
292
293
294 4.2
295
296
297 · use node version: Loads specified NodeJS version.
298
299
300 Example (.envrc):
301
302
303 set -e
304 use node 4.2.2
305
306
307 · watch_file path: Adds a file to direnv's watch-list. If the file
308 changes direnv will reload the environment on the next prompt.
309
310
311 Example (.envrc):
312
313
314 watch_file Gemfile
315
316
317
319 Copyright (C) 2014 zimbatm ⟨http://zimbatm.com⟩ and contributors under
320 the MIT licence.
321
322
324 direnv(1)
325
326
327
328direnv APRIL 2014 DIRENV-STDLIB(1)