Skip to content

Commit 096daa4

Browse files
authored
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.
1 parent 8b40551 commit 096daa4

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

modules/fnm/fnm.nu

+17-9
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,25 @@ export-env {
2323
if not (which fnm | is-empty) {
2424
fnm-env | load-env
2525

26-
if (not ($env | default false __fnm_hooked | get __fnm_hooked)) {
27-
$env.__fnm_hooked = true
28-
$env.config = ($env | default {} config).config
29-
$env.config = ($env.config | default {} hooks)
30-
$env.config = ($env.config | update hooks ($env.config.hooks | default {} env_change))
31-
$env.config = ($env.config | update hooks.env_change ($env.config.hooks.env_change | default [] PWD))
32-
$env.config = ($env.config | update hooks.env_change.PWD ($env.config.hooks.env_change.PWD | append { |before, after|
26+
$env.config = (
27+
$env.config?
28+
| default {}
29+
| upsert hooks { default {} }
30+
| upsert hooks.env_change { default {} }
31+
| upsert hooks.env_change.PWD { default [] }
32+
)
33+
let __fnm_hooked = (
34+
$env.config.hooks.env_change.PWD | any { try { get __fnm_hook } catch { false } }
35+
)
36+
if not $__fnm_hooked {
37+
$env.config.hooks.env_change.PWD = ($env.config.hooks.env_change.PWD | append {
38+
__fnm_hook: true,
39+
code: {|before, after|
3340
if ('FNM_DIR' in $env) and ([.nvmrc .node-version] | path exists | any { |it| $it }) {
34-
(^fnm use); (fnm-env | load-env)
41+
(^fnm use); (fnm-env | load-env)
42+
}
3543
}
36-
}))
44+
})
3745
}
3846
}
3947
}

0 commit comments

Comments
 (0)