1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-02 07:07:46 +00:00

Add direnv config example. (#272)

This commit is contained in:
John Axel Eriksson 2022-08-07 15:25:01 +02:00 committed by GitHub
parent a34f173181
commit a771e04220
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

16
direnv/config.nu Normal file
View file

@ -0,0 +1,16 @@
## 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.
let-env config = {
hooks: {
env_change: {
PWD: [{
code: "
let direnv = (direnv export json | from json)
let direnv = if ($direnv | length) == 1 { $direnv } else { {} }
$direnv | load-env
"
}]
}
}
}