Libraries#

Nu’s re-use layers are built-in commands, the standard library (std, written in Nu, ships with the interpreter), scripts and modules the operator writes or installs, and plugins (compiled binaries that extend the shell with new commands). Beyond the shell, Nu still calls external tools through ^cmd the same way bash does.

Built-in Commands#

The bulk of Nu lives as built-ins implemented in Rust. Browse the category index at https://www.nushell.sh/commands/categories/ or list from the shell.

help commands | length                         # how many built-ins
help commands | where category == "filters"
help commands | where name =~ "http"

Common categories.

Category

Command

filters

where

filters

each

filters

select

filters

sort-by

filters

group-by

filters

uniq

filters

first

filters

last

filters

range

conversions

into int

conversions

into string

conversions

into datetime

conversions

from json

conversions

from csv

conversions

to json

conversions

to csv

strings

str upcase

strings

str trim

strings

str replace

strings

str length

strings

str contains

date

date now

date

date format

date

date list-timezone

filesystem

ls

filesystem

open

filesystem

save

filesystem

cp

filesystem

mv

filesystem

rm

filesystem

mkdir

filesystem

cd

system

sys host

system

sys cpu

system

sys mem

system

sys disks

system

ps

system

which

network

http get

network

http post

network

http put

network

http delete

network

url parse

Standard Library (std)#

The standard library ships with Nu, written in Nu. use std imports it. Modules under std give logging, asserts, formatting, dirs, and helper closures.

use std

std log info "starting"
std log warning "retry"
std log error "failed"

std assert ($x > 0) "x must be positive"
std assert equal $expected $actual

std help                                       # the in-shell help system

Submodules.

  • std/log, structured logging with levels.

  • std/assert, testing-style assertions.

  • std/datetime, date helpers (today, tomorrow, week-start).

  • std/dirs, directory stack (dirs add, dirs next, dirs prev).

  • std/formats, pretty printers.

  • std/iter, iterator helpers.

  • std/help, the help system itself.

Modules#

A module is a .nu file with export def, export const, and export-env declarations. use pulls its commands into the current scope.

# ~/.config/nushell/scripts/myutils.nu
export def hello [name: string] {
    $"hello ($name)"
}
export def --env enter-project [path: path] {
    cd $path
    $env.PROJECT = ($path | path basename)
}
export const VERSION = "1.0"

Import.

use ~/.config/nushell/scripts/myutils.nu *
hello "operator"
print $VERSION

A module can also live in a folder with a mod.nu entry point; use ./mymod then loads the folder.

Plugins#

Plugins are external binaries that speak the Nu plugin protocol and add new commands. They live as nu_plugin_<name> on the filesystem; plugin add registers one, plugin use loads it into the current session.

plugin add ~/.cargo/bin/nu_plugin_polars
plugin use polars

open data.parquet | polars into-df | polars head 10

Common plugins the operator may pull in.

Built-in plugin commands.

plugin list                                    # what is registered
plugin add <binary>                            # register
plugin rm <name>                               # unregister
plugin use <name>                              # load now

External Tools#

Everything not built in is an external program. Same coreutils toolkit bash leans on.

  • Text: grep, sed, awk, cut, tr, sort, uniq

  • Files: find, xargs, stat, rsync

  • Process: ps, pgrep, kill, timeout

  • Containers / cloud: docker, kubectl, aws, gcloud, az

Use the ^ prefix when a Nu built-in shadows the name.

^grep ERROR app.log
^awk '{print $2}' access.log

References#