mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-01 06:37:46 +00:00
Add support for fnm (#593)
* add fnm Signed-off-by: Daniel Sieradski <daniel@self.agency> * restore path list --------- Signed-off-by: Daniel Sieradski <daniel@self.agency>
This commit is contained in:
parent
11bc9c6d33
commit
411496d311
2 changed files with 52 additions and 0 deletions
15
modules/fnm/README.md
Normal file
15
modules/fnm/README.md
Normal file
|
@ -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
modules/fnm/fnm.nu
Normal file
37
modules/fnm/fnm.nu
Normal file
|
@ -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)
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue