DEV Community

Cover image for Using FNM with Nushell
Vaibhav Dwivedi
Vaibhav Dwivedi

Posted on • Edited on

Using FNM with Nushell

A new type of shell

Nushell is a cross-platform shell with a built-in powerful plugin system, but where the Nushell shines is in the way it displays the output.

Output of ls command

Outputs are in table format and can be filtered and sorted.

Output of ls command, filtered to display only the directories sorted by recently modified

The output of ls command, filtered to display only the directories sorted by recently modified.


FNM - Fast Node Manager

FNM describes itself as a fast and simple Node.JS version manager, built in Rust.

Install and configure FNM

  • Open the terminal and switch to Nushell.

  • Install FNM using the following command.

    
    

curl -fsSL https://fnm.vercel.app/install | bash

- Find the Nushell config by running the following command.
Enter fullscreen mode Exit fullscreen mode

$nu.config-path

![$nu.config-path output](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b9z8oii9qn6b20j43gtk.png)
- Open the config file in any text editor like vim and add the following lines at the end.

Enter fullscreen mode Exit fullscreen mode

$env.PATH = ($env.PATH | prepend "/home/vaibhavdn/.fnm")

Here we are adding the location where the FNM was installed to the PATH environment.

Enter fullscreen mode Exit fullscreen mode

load-env (fnm env --shell bash | lines | str replace 'export ' '' | str replace -a '"' '' | split column = | rename name value | where name != "FNM_ARCH" && name != "PATH" | reduce -f {} {|it, acc| $acc | upsert $it.name $it.value })

Then we load the FNM_MULTISHELL_PATH

The output of the command used to load FNM_MULTISHELL_PATH
![Loading FNM multi-shell path](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a8vcbtpbskltb2oc6sgt.png)

Enter fullscreen mode Exit fullscreen mode

$env.PATH = ($env.PATH | prepend $"($env.FNM_MULTISHELL_PATH)/bin")

Finally we add the loaded FNM_MULTISHELL_PATH to the PATH environment.

Save the file and restart the terminal.
FNM is ready to be used now!!

***

Edit - Nov 2023:
Updated syntax to use $env.PATH in place of let-env PATH. Thanks to @treipatru 

***

References
1. https://www.nushell.sh/book/
2. https://github.com/Schniz/fnm
3. https://github.com/Schniz/fnm/issues/463
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
treipatru profile image
Andrei

Thanks for the article! The syntax is a bit out of date for version 0.84.0, but with a few changes it works like a charm.

Here's the updated config:

load-env (fnm env --shell bash
    | lines
    | str replace 'export ' ''
    | str replace -a '"' ''
    | split column =
    | rename name value
    | where name != "FNM_ARCH" and name != "PATH"
    | reduce -f {} {|it, acc| $acc | upsert $it.name $it.value }
)

$env.PATH = ($env.PATH
    | split row (char esep)
    | prepend $"($env.FNM_MULTISHELL_PATH)/bin"
)
Enter fullscreen mode Exit fullscreen mode