From 85da8c2fb5967a7f575d8f63ebeb8d49d36fc139 Mon Sep 17 00:00:00 2001 From: Piepmatz <3590829+cptpiepmatz@users.noreply.github.com> Date: Sat, 7 Oct 2023 16:25:15 +0200 Subject: [PATCH] Use Existing Path Env Var for FNM (#632) The module for `fnm` did not set the path for Windows correctly. I fixed it by searching for the used `Path` variable (or `PATH`) and use that instead. Works now better on Windows without breaking other OSes. --- modules/fnm/fnm.nu | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/modules/fnm/fnm.nu b/modules/fnm/fnm.nu index 0cad349b..7787db85 100644 --- a/modules/fnm/fnm.nu +++ b/modules/fnm/fnm.nu @@ -1,20 +1,22 @@ export-env { def fnm-env [] { mut env_vars = {} - let pwsh_vars = (^fnm env --shell power-shell) - let var_table = ($pwsh_vars - | lines - | parse "$env:{key} = \"{value}\"" + let pwsh_vars = ( + ^fnm env --shell power-shell | + lines | + parse "$env:{key} = \"{value}\"" ) - for v in $var_table { - mut value: any = null - if ($v.key | str downcase) == 'path' { - $value = ($v.value | split row (char esep)) - } else { - $value = $v.value - } - $env_vars = ($env_vars | insert $v.key $value) + + # fnm-prefixed vars + for v in ($pwsh_vars | range 1..) { + $env_vars = ($env_vars | insert $v.key $v.value) } + + # path + let env_used_path = ($env | columns | where {str downcase | $in == "path"} | get 0) + let path_value = ($pwsh_vars | get 0.value | split row (char esep)) + $env_vars = ($env_vars | insert $env_used_path $path_value) + return $env_vars }