nushell

From Gentoo Wiki
Jump to:navigation Jump to:search
This page contains changes which are not marked for translation.
Other languages:
  • English

Nushell is a new kind of shell for OS X, Linux, and Windows. Nushell uses structured data allowing for powerful but simple pipelines. It offers great error messages, completions and works with existing datatypes.

Important
As with the fish shell, Nushell is not a POSIX-compatible shell. It could cause issues if improperly set as a user's login shell. Refer to the "Caveats" section for how to safely set nushell as a user's default shell.
Warning
Nushell should not be set as the system shell by making it the target of the /bin/sh symlink; this could result in an inoperable system.

Installation

USE flags

USE flags for app-shells/nushell A new type of shell, written in Rust

X Add support for X11
debug Enable extra debug codepaths, like asserts and extra output. If you want to get meaningful backtraces see https://wiki.gentoo.org/wiki/Project:Quality_Assurance/Backtraces
mcp Build MCP server
plugins Build official plugins
system-clipboard System clipboard support in `reedline`
Data provided by the Gentoo Package Database · Last update: 2026年08月24日 21:19 More information about USE flags

Emerge

Install app-shells/nushell :

root #emerge --ask app-shells/nushell

Caveats

Nushell is not POSIX-compatible, thus it is strongly advised not to set Nushell as the login shell for any user. Refer to the discussion for the fish shell for more details.

A simple working solution is to start nushell from the terminal, as advised in the official documentation.

To use nushell as the default login shell, ~/.bashrc can be used to have nushell inherit the environment from the login shell, which is left as Bash. Add the following to the user's ~/.bashrc, making sure it's placed below the test for an interactive shell, e.g. at the end of the file:

FILE ~/.bashrc
[...]
# Use nushell in place of bash
# keep this line at the bottom of ~/.bashrc
[-x/usr/bin/nu]&&SHELL=/usr/bin/nuexecnu

When bash is started as an interactive shell, this will automatically launch nushell for the user, once bash has fully initialized the correct system environment. It will also set the SHELL environment variable to /usr/bin/nu in nushell.

Features

In Nushell, data is structured as tables. This allows one to query, filter and sort easily. For example, a search for all Emacs processes can be done with:

user $ps | name =~ emacs

List files with older first:

user $ls | sort-by modified

Getting the basename of several files:

user $ls *.png | get name | path parse | get stem

Applying a command to each line in the table can done using a closure with each. Converting all Org-mode files in a directory to Markdown is a good illustration of a closure and string substitution:

user $ls *.org | each {|e| pandoc $e.name -o $"($e.name | path parse | get stem).md"}

Thanks to string substitution, it allows for complex but natural commands that would have been rather awkward in Bash.

Configuration

Nushell creates a default configuration file in ~/.config/nushell/config.nu. Alternatively, one could access said file with

user $config nu

However, one needs to note that the default editor (config.buffer_editor) is needed to be set first in order to use this method. One could simply invoke

user $$env.config.buffer_editor = "vi"

to initialize it within the current session to be able to run config nu.

Disabling the welcome banner is done with:

FILE ~/.config/nushell/config.nu
$env.config.show_banner = false # true or false to enable or disable the welcome banner at startup

Changing the theme requires defining and enabling a theme with:

FILE ~/.config/nushell/config.nu
$env.config = {
 color_config: $dark_theme # if you want a more interesting theme, you can replace the empty record with `$dark_theme`, `$light_theme` or another custom record
}

Due to Nushell development, updates may break the configuration file.

Also please note that by defining config variable under the config file, you are actually defining the key-value pair (akin to dictionary) of the said config. Hence, welcome banner example is a preferable way if you are intended to fix just a few key-value pairs rather than the entire environment like changing the theme.

Environment variables

Environment variables can be set up in the current session with:

user $$env.FOO = 'BAR'

PATH is a list of strings so appending a new location can be done with:

user $$env.PATH = ($env.PATH | prepend "/home/USER/.juliaup/bin")

Or, alternatively

user $$env.PATH ++= ["/home/USER/.juliaup/bin"]

as Nushell store PATH as a list, of which one could append it directly.

To define environment variables in all sessions, put them in ~/.config/nushell/env.nu.

Tips

SSH agent

Since eval is not available in nushell, several workarounds exist. One option is to run ssh-agent as a user service.

For example, with systemd create:

~/.config/systemd/user/ssh-agent.service

[Unit]
Description=SSH key agent
[Service]
Type=simple
Environment=SSH_AUTH_SOCK=%t/ssh-agent.socket
ExecStart=/usr/bin/ssh-agent -D -a $SSH_AUTH_SOCK
[Install]
WantedBy=default.target

Then add the following to ~/.bash_profile:

exportSSH_AUTH_SOCK=/run/user/1000/ssh-agent.socket
ssh-add"$HOME/.ssh/id_ed25519"

Using Nushell with Nix

The modifications to ~/.bashrc described above prevent Nushell from applying its environment variable configuration. Nix users can use the following variant to work around this problem by disabling Nushell execution within a nix-shell:

FILE ~/.bashrc
[...]
# Use nushell in place of bash
# keep this line at the bottom of ~/.bashrc
[-x/usr/bin/nu]&&[-z"$IN_NIX_SHELL"]&&SHELL=/usr/bin/nuexecnu

With this configuration in place, running nix-shell will result in a Bash shell. To start a nix-shell with Nushell, use nix-shell --command nushell, which will correctly apply the Nix environment before launching Nushell.

Sudo inside Doom Emacs

Accessing files with sudo inside Emacs fails as it cannot run the /bin/sh -i command. Setting Emacs' shell-file-name variable to /bin/bash does not work. A simple way to get around it is to reconfigure the SHELL environment variable for Doom Emacs with:

user $SHELL="/bin/bash" ~/.emacs.d/bin/doom env

Signing Git commit messages with GPG

If it fails with gpg: signing failed: Inappropriate ioctl for device, set GPG_TTY to the output of tty with:

user $$env.GPG_TTY = (tty)

Interactive news item reading

To read eselect news in a more interactive manner, one could take advantage of Nushell's features such as parsing and fuzzy input:

CODE Nushell script to read eselect news
eselect--briefnewslistall
|parse--regex'\s*(?P<Unread>N)?\s*(?P<Date>\d{4}-\d{2}-\d{2})\s*(?P<Title>.+)'
|updateUnread{|row|if$row.Unread=='N'{true}else{false}}
|updateDate{intodatetime}
|getTitle
|inputlist--fuzzy--index
|sudoeselectnewsread$"($in + 1)"

This could be further customized to only read news from a certain period by adding an additional pipe like | where Date > (date now) - 2wk to only read items for the past two weeks.

Python virtual environment

While default venv does not provide the activate script to initialize the python environment, dev-python/virtualenv does provide said script.

First, start by creating the environment

user $python -m virtualenv testenv

This will create the ./testenv directory similar to how venv create the virtual environment. From here, one can simply invoke

user $overlay use ./testenv/bin/activate.nu

to activate said environment.


See also

  • Shell — command-line interpreter that provides a text-based interface to users
  • Bash — the default shell on Gentoo systems and a popular shell program found on many Linux systems.
  • Dash — a small, fast, and POSIX-compliant shell.
  • Zsh — an interactive login shell that can also be used as a powerful scripting language interpreter.
  • Fish — a smart and user-friendly command line shell for OS X, Linux, and the rest of the family.


External resources