Skip to content

Commit

Permalink
Use Existing Path Env Var for FNM (nushell#632)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cptpiepmatz authored Oct 7, 2023
1 parent c9d6394 commit 85da8c2
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions modules/fnm/fnm.nu
Original file line number Diff line number Diff line change
@@ -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
}

Expand Down

0 comments on commit 85da8c2

Please sign in to comment.