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