Skip to content

Commit

Permalink
update fnm script
Browse files Browse the repository at this point in the history
  • Loading branch information
myty committed Apr 4, 2024
1 parent 032c131 commit 3e8a27f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
3 changes: 1 addition & 2 deletions nushell/config.nu
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ source "~/.config/dotfiles/nushell/commands.nu"
use "~/.config/dotfiles/nushell/nu_scripts/custom-completions/git/git-completions.nu" *
use "~/.config/dotfiles/nushell/nu_scripts/custom-completions/npm/npm-completions.nu" *
use "~/.config/dotfiles/nushell/nu_scripts/custom-completions/scoop/scoop-completions.nu" *
# use "~/.config/dotfiles/nushell/nu_scripts/custom-completions/winget/winget-completions.nu" *

use "~/.config/dotfiles/nushell/nu_scripts/modules/fnm/fnm.nu"
source "~/.config/dotfiles/nushell/scripts/fnm.nu"

# Load Starship
source ~/.cache/starship/init.nu
29 changes: 29 additions & 0 deletions nushell/scripts/fnm.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export-env {
$env.config = ($env.config | upsert hooks {
env_change: {
PWD: ($env.config.hooks.env_change.PWD ++
[{
condition: {|before, after| [.nvmrc .node-version] | path exists | any { |it| $it }}
code: {|before, after|
if ('FNM_DIR' in $env) {
fnm --log-level=quiet use
}
}
}]
)
}
})
}


if not (which fnm | is-empty) {
^fnm env --json | from json | load-env
# Checking `Path` for Windows
let path = if 'Path' in $env { $env.Path } else { $env.PATH }
let node_path = if (sys).host.name == 'Windows' {
$"($env.FNM_MULTISHELL_PATH)"
} else {
$"($env.FNM_MULTISHELL_PATH)/bin"
}
$env.PATH = ($path | prepend [ $node_path ])
}

0 comments on commit 3e8a27f

Please sign in to comment.