Skip to content

Commit

Permalink
Add support for fnm (#593)
Browse files Browse the repository at this point in the history
* add fnm

Signed-off-by: Daniel Sieradski <daniel@self.agency>

* restore path list

---------

Signed-off-by: Daniel Sieradski <daniel@self.agency>
  • Loading branch information
selfagency authored Sep 8, 2023
1 parent 11bc9c6 commit 411496d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
15 changes: 15 additions & 0 deletions modules/fnm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Fast Node Manager (fnm)

Enables Nushell support for [Fast Node Manager (fnm)](https://github.com/Schniz/fnm), a fast and simple Node.js version manager. Based on [this GitHub issue](https://github.com/Schniz/fnm/issues/463) and [fnm-nushell](https://github.com/Southclaws/fnm-nushell).

Requires `fnm` to be installed separately.

## Install

Clone this repo or copy the `fnm.nu` file wherever your prefer to keep your Nushell scripts.

Edit your Nushell config file (`$nu.config-path`) and add the line:

```nu
use /path/to/fnm.nu
```
37 changes: 37 additions & 0 deletions modules/fnm/fnm.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
export-env {
def fnm-env [] {
mut env_vars = {}
let pwsh_vars = (^fnm env --shell power-shell)
let var_table = ($pwsh_vars
| lines
| parse "$env:{key} = \"{value}\""
)
for v in $var_table {
mut value: any = null
if ($v.key | str downcase) == 'path' {
$value = ($v.value | split row (char esep))
} else {
$value = $v.value
}
$env_vars = ($env_vars | insert $v.key $value)
}
return $env_vars
}

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|
if ('FNM_DIR' in $env) and ([.nvmrc .node-version] | path exists | any { |it| $it }) {
(^fnm use); (fnm-env | load-env)
}
}))
}
}
}

0 comments on commit 411496d

Please sign in to comment.