nushell
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. Refer to the "Caveats" section for how to safely set nushell as a user's default shell.
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
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:
[...]
# 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.
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. Disabling the welcome banner is done with
$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:
$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 strings 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/env.nu.
Tips
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:
[...]
# 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 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:
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.