From 54f13b39f62cbc1a05fc8f7613cb9cc1b9293dbb Mon Sep 17 00:00:00 2001 From: Michael Tyson Date: Wed, 11 Sep 2024 08:52:38 -0400 Subject: [PATCH] update fnm script --- install.nu | 9 ++++++--- nushell/config.nu | 2 +- nushell/modules/fnm/fnm.nu | 23 +++++++++++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 nushell/modules/fnm/fnm.nu diff --git a/install.nu b/install.nu index 4636a7a..99dae57 100644 --- a/install.nu +++ b/install.nu @@ -1,9 +1,12 @@ -let host_name = (sys host | get name) -let home_path = if host_name == "Windows" {$env.USERPROFILE} else {$env.HOME} +let home_path = match $nu.os-info.name { + "windows" => $"($env.USERPROFILE)", + _ => $"($env.HOME)", + } + let dotfiles_symlink_path = $"($home_path)/.config/dotfiles" if (($dotfiles_symlink_path | path exists) != true) { - if host_name == "Windows" { + if $nu.os-info.name == "windows" { ^mklink /d $"($dotfiles_symlink_path)" $"($env.PWD)" } else { ^ln -s $env.PWD $dotfiles_symlink_path diff --git a/nushell/config.nu b/nushell/config.nu index 0650c14..f511dff 100644 --- a/nushell/config.nu +++ b/nushell/config.nu @@ -9,7 +9,7 @@ use "~/.config/dotfiles/nushell/nu_scripts/custom-completions/git/git-completion 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/modules/fnm/fnm.nu" +source ./modules/fnm/fnm.nu # Load rbenv # TODO: Move to ~/.nushellrc for MacOS diff --git a/nushell/modules/fnm/fnm.nu b/nushell/modules/fnm/fnm.nu new file mode 100644 index 0000000..9995720 --- /dev/null +++ b/nushell/modules/fnm/fnm.nu @@ -0,0 +1,23 @@ +if not (which fnm | is-empty) { + ^fnm env --resolve-engines --corepack-enabled --json | from json | load-env + + let node_path = match $nu.os-info.name { + "windows" => $"($env.FNM_MULTISHELL_PATH)", + _ => $"($env.FNM_MULTISHELL_PATH)/bin", + } + $env.PATH = ($env.PATH | prepend [ $node_path ]) +} + +$env.config = ($env.config | merge { + hooks: { + env_change: { + PWD: [{ + if ([.nvmrc .node-version] | path exists | any { |it| $it }) { + fnm use + } else { + fnm --log-level=quiet use default + } + }] + } + } +})