DEV Community

Cover image for Using FNM with Nushell
Vaibhav Dwivedi
Vaibhav Dwivedi

Posted on • Updated 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
Enter fullscreen mode Exit fullscreen mode
  • Find the Nushell config by running the following command.
$nu.config-path
Enter fullscreen mode Exit fullscreen mode

$nu.config-path output

  • Open the config file in any text editor like vim and add the following lines at the end.
$env.PATH = ($env.PATH | prepend "/home/vaibhavdn/.fnm")
Enter fullscreen mode Exit fullscreen mode

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

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 })
Enter fullscreen mode Exit fullscreen mode

Then we load the FNM_MULTISHELL_PATH

The output of the command used to load FNM_MULTISHELL_PATH
Loading FNM multi-shell path

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

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

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