1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-01 22:57:46 +00:00

fix(fnm): Automatic version switching failed. (#1064)

![image](https://github.com/user-attachments/assets/c31f7a3a-e312-4773-bb25-5e3c10747bd6)
This commit is contained in:
ziboh 2025-03-07 21:09:20 +08:00 committed by GitHub
parent c517cd0075
commit 10fc3797e0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,9 +2,7 @@ export-env {
def fnm-env [] { def fnm-env [] {
mut env_vars = {} mut env_vars = {}
let pwsh_vars = ( let pwsh_vars = (
^fnm env --shell power-shell | ^fnm env --shell power-shell | lines | parse "$env:{key} = \"{value}\""
lines |
parse "$env:{key} = \"{value}\""
) )
# fnm-prefixed vars # fnm-prefixed vars
@ -13,7 +11,7 @@ export-env {
} }
# path # path
let env_used_path = ($env | columns | where {str downcase | $in == "path"} | get 0) 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)) let path_value = ($pwsh_vars | get 0.value | split row (char esep))
$env_vars = ($env_vars | insert $env_used_path $path_value) $env_vars = ($env_vars | insert $env_used_path $path_value)
@ -34,14 +32,16 @@ export-env {
$env.config.hooks.env_change.PWD | any { try { get __fnm_hook } catch { false } } $env.config.hooks.env_change.PWD | any { try { get __fnm_hook } catch { false } }
) )
if not $__fnm_hooked { if not $__fnm_hooked {
$env.config.hooks.env_change.PWD = ($env.config.hooks.env_change.PWD | append { $env.config.hooks.env_change.PWD = (
__fnm_hook: true, $env.config.hooks.env_change.PWD | append {
__fnm_hook: true
code: {|before, after| code: {|before, after|
if ('FNM_DIR' in $env) and ([.nvmrc .node-version] | path exists | any { |it| $it }) { if ('FNM_DIR' in $env) and ([.nvmrc .node-version] | path exists | any {|it| $it }) {
(^fnm use); (fnm-env | load-env) ^fnm use
} }
} }
}) }
)
} }
} }
} }