From df90d65eeca2528a078a4b62ece1c626174fd168 Mon Sep 17 00:00:00 2001 From: Piepmatz Date: Wed, 3 Apr 2024 13:49:41 +0200 Subject: [PATCH] Add `from env` (#808) This adds a little command that allows opening .env files as records. My implementation removes comments and works with both quoted and unquoted .env files. --- modules/formats/from-env.nu | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 modules/formats/from-env.nu diff --git a/modules/formats/from-env.nu b/modules/formats/from-env.nu new file mode 100644 index 00000000..458f2604 --- /dev/null +++ b/modules/formats/from-env.nu @@ -0,0 +1,11 @@ +# Converts a .env file into a record +# may be used like this: open .env | load-env +# works with quoted and unquoted .env files +def "from env" []: string -> record { + lines + | split column '#' # remove comments + | get column1 + | parse "{key}={value}" + | str trim value -c '"' # unquote values + | transpose -r -d +}