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

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.

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. See caveats section for how to set nushell as a user's default shell safely.
nushell should not be set as the system shell by linking in /bin/sh, this could result in an inoperable system.


USE flags

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

X Add support for X11
dataframe Dataframe feature for nushell
debug Enable extra debug codepaths, like asserts and extra output. If you want to get meaningful backtraces see
extra Enable less stable or less common commands
plugins Build official plugins


Install app-shells/nushell:

root #emerge --ask app-shells/nushell


nushell is not POSIX compatible, thus it is strongly advised not to set nushell as the login shell for any user. See the discussion for fish shell for more details. A simple working solution is to start nushell from bash, as described below.

nushell as a default shell with bash as the login shell

This solution was suggested for the fish shell and the use of nushell by default, upon login or on starting a terminal emulator. This solution uses ~/.bashrc as a wrapper to have nushell inherit the environment from the login shell, which is left as a 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/nu exec nu

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.


In nushell, data is structured as tables. This allows to query, filter and sort easily. For example, 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 $ -o $"($ | path parse | get stem).md"}

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


nushell create a default configuration file in in ~/.config/nushell/ Disabling the welcome banner is done with

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

Changing the theme needs one to be defined in (default are $light_theme and $dark_theme) and enabled with

FILE ~/.config/nushell/
$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.

Environment variables

Envinnoment variables can be set up in the current session with

user $$env.FOO = 'BAR'

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

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

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


Using Nushell with Nix

The bashrc method from the "fish as a default shell with bash as the login shell" section above prevents nix-shell from applying its environment variable configuration. Nix users can use the following variant to work around this problem by disabling fish 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/nu exec nu

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

Sudo inside Doom Emacs

Accessing files with sudo inside emacs fails as it cannot run /bin/sh -i command. Setting shell-file-name 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 --brief news list all
| parse --regex '\s*(?P<Unread>N)?\s*(?P<Date>\d{4}-\d{2}-\d{2})\s*(?P<Title>.+)'
| update Unread { |row| if $row.Unread == 'N' { true } else { false } }
| update Date { into datetime }
| get Title
| input list --fuzzy --index
| sudo eselect news read $"($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.

See also

  • Shell — command-line interpreter that offers 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