From a73d897c092acb01dcb826748c93c4020024f09e Mon Sep 17 00:00:00 2001 From: NotTheDr01ds <32344964+NotTheDr01ds@users.noreply.github.com> Date: Mon, 14 Apr 2025 20:22:46 -0400 Subject: [PATCH 1/2] Add note to direnv example --- nu-hooks/nu-hooks/direnv/config.nu | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nu-hooks/nu-hooks/direnv/config.nu b/nu-hooks/nu-hooks/direnv/config.nu index 2cb7efc7..f19840dd 100644 --- a/nu-hooks/nu-hooks/direnv/config.nu +++ b/nu-hooks/nu-hooks/direnv/config.nu @@ -1,3 +1,6 @@ +# This file includes several examples of how you might use hooks to enable direnv with Nushell. +# Please see the [Cookbook](https://www.nushell.sh/cookbook/direnv.html) for the latest recommendations. + # you can use the following closure in your config in a few different ways, e.g. # # ```nushell From 5ffe0aa42aa9f4c7ab7d4cf6996b002a96912bdf Mon Sep 17 00:00:00 2001 From: NotTheDr01ds <32344964+NotTheDr01ds@users.noreply.github.com> Date: Mon, 14 Apr 2025 20:33:40 -0400 Subject: [PATCH 2/2] Remove direnv config.nu and make Cookbook version definitive --- nu-hooks/nu-hooks/direnv/config.nu | 33 ------------------------------ 1 file changed, 33 deletions(-) delete mode 100644 nu-hooks/nu-hooks/direnv/config.nu diff --git a/nu-hooks/nu-hooks/direnv/config.nu b/nu-hooks/nu-hooks/direnv/config.nu deleted file mode 100644 index f19840dd..00000000 --- a/nu-hooks/nu-hooks/direnv/config.nu +++ /dev/null @@ -1,33 +0,0 @@ -# This file includes several examples of how you might use hooks to enable direnv with Nushell. -# Please see the [Cookbook](https://www.nushell.sh/cookbook/direnv.html) for the latest recommendations. - -# you can use the following closure in your config in a few different ways, e.g. -# -# ```nushell -# $env.config.hooks.env_change.PWD = ( -# $env.config.hooks.env_change.PWD | append (source nu-hooks/nu-hooks/direnv/config.nu) -# ) -# ``` -# -# or -# -# ```nushell -# $env.config.hooks.pre_prompt = ( -# $env.config.hooks.pre_prompt | append (source nu-hooks/nu-hooks/direnv/config.nu) -# ) -# ``` -# -# > :bulb: **Note** -# > the former will update direnv when you enter and leave a directory whereas the later will update -# > on every new prompt, i.e. much more often. -{ || - if (which direnv | is-empty) { - return - } - - direnv export json | from json | default {} | load-env - # Direnv outputs $PATH as a string, but nushell silently breaks if isn't a list-like table. - # The following behemoth of Nu code turns this into nu's format while following the standards of how to handle quotes, use it if you need quote handling instead of the line below it: - # $env.PATH = $env.PATH | parse --regex ('' + `((?:(?:"(?:(?:\\[\\"])|.)*?")|(?:'.*?')|[^` + (char env_sep) + `]*)*)`) | each {|x| $x.capture0 | parse --regex `(?:"((?:(?:\\"|.))*?)")|(?:'(.*?)')|([^'"]*)` | each {|y| if ($y.capture0 != "") { $y.capture0 | str replace -ar `\\([\\"])` `$1` } else if ($y.capture1 != "") { $y.capture1 } else $y.capture2 } | str join } - $env.PATH = $env.PATH | split row (char env_sep) -}