chore(nu): automatically set the node_modules bin dir on cd

When we are moving around the file system I always want to be able to use the
locally installed executables from my node modules.

Sometimes versions of programs like prettier have different outcomes. I always
want to be using the local version rather than the system installed version.
This commit is contained in:
Ade Attwood 2025-01-21 08:19:38 +00:00
parent d7a955f103
commit c482f7a612
2 changed files with 14 additions and 1 deletions

View file

@ -1,4 +1,4 @@
use path.nu
use path.nu *
use fzf.nu *
use neovim.nu *
@ -16,6 +16,7 @@ $env.config = {
PWD: [
{|_, after| nvm dir-hook $after }
{|_, after| rvm-dir-hook $after }
{|_, after| node-modules-dir-hook $after }
]
}
}

View file

@ -6,3 +6,15 @@ export-env {
| prepend ([$env.HOME ".cargo" "bin"] | path join)
| str join ":"
}
export def --env node-modules-dir-hook [dir: string] {
let nodePath = ([$dir, "node_modules", ".bin"] | path join)
if ($nodePath | path exists) {
$env.PATH = $env.PATH
| split row ":"
| where {|x| not ($x | str contains "node_modules")}
| prepend $nodePath
| str join ":"
}
}