1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-07-31 14:17:45 +00:00

Fix the fnm bug of Nushell reloading (#1058)

![image](https://github.com/user-attachments/assets/a528e891-1be3-4e87-ba5b-6f3f989177a6)
Opening a terminal in nvim results in the error shown above.
This commit is contained in:
ziboh 2025-02-25 20:22:18 +08:00 committed by GitHub
parent 8b40551de7
commit 096daa436d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -23,17 +23,25 @@ export-env {
if not (which fnm | is-empty) {
fnm-env | load-env
if (not ($env | default false __fnm_hooked | get __fnm_hooked)) {
$env.__fnm_hooked = true
$env.config = ($env | default {} config).config
$env.config = ($env.config | default {} hooks)
$env.config = ($env.config | update hooks ($env.config.hooks | default {} env_change))
$env.config = ($env.config | update hooks.env_change ($env.config.hooks.env_change | default [] PWD))
$env.config = ($env.config | update hooks.env_change.PWD ($env.config.hooks.env_change.PWD | append { |before, after|
$env.config = (
$env.config?
| default {}
| upsert hooks { default {} }
| upsert hooks.env_change { default {} }
| upsert hooks.env_change.PWD { default [] }
)
let __fnm_hooked = (
$env.config.hooks.env_change.PWD | any { try { get __fnm_hook } catch { false } }
)
if not $__fnm_hooked {
$env.config.hooks.env_change.PWD = ($env.config.hooks.env_change.PWD | append {
__fnm_hook: true,
code: {|before, after|
if ('FNM_DIR' in $env) and ([.nvmrc .node-version] | path exists | any { |it| $it }) {
(^fnm use); (fnm-env | load-env)
(^fnm use); (fnm-env | load-env)
}
}
}))
})
}
}
}