From e245718d308b107997b34e408df72acba395590a Mon Sep 17 00:00:00 2001 From: Xavier Ruiz Date: Sat, 25 Jan 2025 19:19:36 -0500 Subject: [PATCH] fix "from env" newline handling (#1021) Many (at least the ones I have encountered) env loaders replace "\n" with a literal newline character when loading an env variable. I need this change in my personal config and I think others would also prefer this default. --- modules/formats/from-env.nu | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/formats/from-env.nu b/modules/formats/from-env.nu index 458f260..09ec1e5 100644 --- a/modules/formats/from-env.nu +++ b/modules/formats/from-env.nu @@ -2,10 +2,15 @@ # may be used like this: open .env | load-env # works with quoted and unquoted .env files def "from env" []: string -> record { - lines + lines | split column '#' # remove comments - | get column1 + | get column1 | parse "{key}={value}" - | str trim value -c '"' # unquote values + | update value { + str trim -c '"' | # unquote values + str replace -a "\\n" "\n" # replace `\n` with newline char + str replace -a "\\r" "\r" # replace `\r` with carriage return + str replace -a "\\t" "\t" # replace `\t` with tab + } | transpose -r -d }