From a771e04220d632cfdac94374fc81dbf1b43c2c9f Mon Sep 17 00:00:00 2001 From: John Axel Eriksson Date: Sun, 7 Aug 2022 15:25:01 +0200 Subject: [PATCH] Add direnv config example. (#272) --- direnv/config.nu | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 direnv/config.nu diff --git a/direnv/config.nu b/direnv/config.nu new file mode 100644 index 0000000..24d29f2 --- /dev/null +++ b/direnv/config.nu @@ -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 + " + }] + } + } +}