You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: cookbook/direnv.md
+34-23Lines changed: 34 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,35 +4,46 @@ title: Direnv
4
4
5
5
# Direnv
6
6
7
-
Many people use [direnv](https://direnv.net) to load an environment upon entering a directory as well as unloading it when exiting the directory.
8
-
Configuring direnv to work with nushell requires nushell version 0.66 or later.
7
+
Many people use [direnv](https://direnv.net) to load an environment when entering a directory and unload it when exiting the directory.
9
8
10
-
---
9
+
## How direnv works
10
+
11
+
From [direnv.net](https://direnv.net):
12
+
13
+
> Before each prompt, direnv checks for the existence of a `.envrc` file (and optionally a `.env` file) in the current and parent directories. If the file exists (and is authorized), it is loaded into a bash sub-shell and all exported variables are then captured by direnv and then made available to the current shell.
14
+
15
+
## Configuring direnv in Nushell
16
+
17
+
In Nushell, it's possible to run direnv each time the prompt displays (using a [`pre_prompt` hook](/book/hooks.html)). However, it's more efficient to update only when the directory is changed using an `env_change` hook along with:
18
+
19
+
-[`from json`](/commands/docs/from_json.md) to convert the direnv output to structured data
20
+
-[`load-env`](/commands/docs/load-env.md)
21
+
- An `env-conversion` helper for the `PATH` from the [Standard Library](/book/standard_library.md)
11
22
12
-
### Configuring direnv
23
+
::: note
13
24
14
-
To make direnv work with nushell the way it does with other shells, we can use the "hooks" functionality:
25
+
The direnv configuration below requires Nushell 0.104 or later.
0 commit comments