forked from nushell/nu_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.nu
14 lines (13 loc) · 825 Bytes
/
config.nu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
## To enable direnv in nushell we must run code in the context of the current shell - i.e it cannot be within a block and it needs to run as a "code" string as per https://github.com/nushell/nushell/pull/5982 (so you must run nushell 0.66 or later). That way it works as if you'd typed in and run the code directly in your shell.
## Direnv knows what to do otherwise and will export the env to load (or unload) based on what is in your current environment so this is all that is needed with some checks for empty strings, defaulting then to an empty table so that load-env is always happy.
$env.config = {
hooks: {
pre_prompt: [{
code: "
let direnv = (direnv export json | from json)
let direnv = if ($direnv | length) == 1 { $direnv } else { {} }
$direnv | load-env
"
}]
}
}