From e7768b4da8ab3c999662180b040ded76a06213e1 Mon Sep 17 00:00:00 2001 From: Julius Riegel Date: Thu, 14 Nov 2024 14:59:08 +0100 Subject: [PATCH] Improve dotenv parsing --- content/config/nushell/env.nu.tmpl | 5 +++++ content/config/nushell/scripts/utils.nu | 14 +++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/content/config/nushell/env.nu.tmpl b/content/config/nushell/env.nu.tmpl index 631b122..2cb7209 100644 --- a/content/config/nushell/env.nu.tmpl +++ b/content/config/nushell/env.nu.tmpl @@ -98,3 +98,8 @@ $env.LTEX_GLOBAL_STORAGE_PATH = "{{dirs.data}}/ltex/" {{#if-installed librewolf}} $env.BROWSER = "librewolf" {{/if-installed}} + +{{#if (eq ctx.environment "unitb")}} +$env.OPENSSL_DIR = "/home/linuxbrew/.linuxbrew" +$env.OPENSSL_STATIC = true +{{/if}} diff --git a/content/config/nushell/scripts/utils.nu b/content/config/nushell/scripts/utils.nu index fd06bb6..6d1f59e 100644 --- a/content/config/nushell/scripts/utils.nu +++ b/content/config/nushell/scripts/utils.nu @@ -95,7 +95,19 @@ export def --env dotenv [file=".env"] { } ( open $file | lines - | each { parse "{key}={value}" | first | { $in.key: $in.value} } + | where $it !~ "^\\s*#.*" + | each {|line| + try { + $line | parse "{key}=\"{value}\"" | first | { $in.key: ($"\"($in.value)\"" | from nuon) } + } catch { + try { + $line | parse "{key}={value}" | first | { $in.key: $in.value } + } catch { + null + } + } + } + | where $it != null | reduce --fold {} {|it, acc| $acc | merge $it } | load-env $in )