Nushell is a pretty cool project written in Rust to have a shell working the same on all platforms. It can notably be extended with plugins. But figuring out how to install them from their instructions and, even after this, the many steps required, ruined my excitement. Here’s how I made it exciting again! 🚀
Install once
Install Rust, GCC and Git. There are detailed steps below for Windows, OSX and Linux if you need to install any.
Launch a Nushell terminal
Setup a custom command
install_plugin
in your Nushell configuration:echo " def install_plugin [plugin_name: string, git_repository_url?: string, git_tag?: string] { mut cargo_install_flags = {} # Git repository URL defaults to Nushell repository. if ($git_repository_url == null) { $cargo_install_flags = ($cargo_install_flags | insert "--git" "https://github.com/nushell/nushell.git") } else { $cargo_install_flags = ($cargo_install_flags | insert "--git" $git_repository_url) } # If the repository URL is the Nushell repository, the tag defaults to # the current Nushell version. if $git_tag != null and $git_tag != "" { $cargo_install_flags = ($cargo_install_flags | insert "--tag" $git_tag) } else if ($cargo_install_flags | get "--git") == "https://github.com/nushell/nushell.git" { $cargo_install_flags = ($cargo_install_flags | insert "--tag" (version | get version)) } let flags = ($cargo_install_flags | items {|key, value| echo $'($key) ($value)' } | str join " ") nu -c $"cargo install ($flags) nu_plugin_($plugin_name)"; const home_directory = ("~" | path expand) let cargo_bin_directory = $"($home_directory)/.cargo/bin" mut plugin_path = $"($cargo_bin_directory)/nu_plugin_($plugin_name)" if (sys).host.name == "Windows" { $plugin_path += ".exe" } nu -c $"register ($plugin_path)" } " | save $nu.config-path --append
Reload the configuration file with
source $nu.config-path
Installing a plugin
Find which plugin you want from awesome-nu#plugins. Let’s say
nu_plugin_gstat
for example.In a Nushell terminal, you can use the
install_plugin
custom command:Usage: > install_plugin <plugin_name> (git_repository_url) (git_tag) Flags: -h, --help - Display the help message for this command Parameters: plugin_name <string>: git_repository_url <string>: (optional) git_tag <string>: (optional)
For plugins:
- from the Nushell repository, run
install_plugin plugin_name
, for exampleinstall_plugin gstat
- For plugins on other repositories, run
install_plugin plugin_name git_repository_url (git_tag)
, for exampleinstall_plugin qr_maker https://github.com/FMotalleb/nu_plugin_qr_maker.git
- from the Nushell repository, run
What steps did we save here? 🕥
- Cloning or downloading manually repositories hosting plugins
- Keeping the Nushell repository locally in sync with the release of Nushell you are running
- Running one command to build the plugin and one to register it
- Saving the repetitive keystrokes to write the plugin prefix
nu_plugin_
in its name 😉
Further improvements
- The second custom command line
nu -c $'register ~/.cargo/bin/($plugin_name).exe'
is a bit obscure, since running directlyregister $'~/.cargo/bin/($plugin_name).exe'
gives the errorValue is not a parse-time constant
. It would be nice to allow variable names, since anyway it’s feasible usingnu -c
. I created issue #11556 to track this.
Install Rust, GCC and Git
The following describes how to install the required tools to install Nushell plugins for Windows, OSX and Linux.
Windows
Ensure you have the Microsoft Winget installed. You can install it with the Microsoft Store or by downloading the Winget installer or with this Powershell code:
$URL = (Invoke-WebRequest -Uri "https://api.github.com/repos/microsoft/winget-cli/releases/latest").Content | ConvertFrom-Json | Select-Object -ExpandProperty "assets" | Where-Object "browser_download_url" -Match '.msixbundle' | Select-Object -ExpandProperty "browser_download_url" Invoke-WebRequest -Uri $URL -OutFile "Setup.msix" -UseBasicParsing Add-AppxPackage -Path "Setup.msix" Remove-Item "Setup.msix"
Ensure you have Chocolatey installed, you can install it with:
if (-not (Get-Command choco -ErrorAction SilentlyContinue)) { Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) }
Chocolatey is required for now to install MinGW which winget doesn’t support yet.
Install Rust, MinGW and Git with this Powershell code:
winget install Rustlang.Rust.GNU Cygwin.Cygwin Git.Git if ($env:USERNAME -eq 'SYSTEM') { choco install -y mingw } else { Start-Process -FilePath "choco.exe" -ArgumentList "install -y mingw" -Verb RunAs -Wait } $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
OSX
Ensure you have brew installed, you can install it with:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Install Rust, GCC and Git with:
brew install rust gcc git
Linux
- Ubuntu:
sudo apt install -y rustc gcc git
- Fedora:
sudo dnf install -y rust gcc git
- Arch:
sudo pacman -Sy rust gcc git
- Alpine:
sudo apk add rust gcc git
Comments