-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add fnm Signed-off-by: Daniel Sieradski <daniel@self.agency> * restore path list --------- Signed-off-by: Daniel Sieradski <daniel@self.agency>
- Loading branch information
1 parent
11bc9c6
commit 411496d
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
})) | ||
} | ||
} | ||
} |