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 |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.
polars, DataFrames for Nu (parquet, SQL, joins, group-by) using Apache Arrow.
nu_plugin_query,
query xml,query web,query jsonselectors.nu_plugin_inc, semantic version increment.
nu_plugin_formats, extra format readers (EML, vCard, INI, plist).
nu_plugin_gstat, git status as a record.
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,uniqFiles:
find,xargs,stat,rsyncProcess:
ps,pgrep,kill,timeoutContainers / 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#
Frameworks for the broader Nu ecosystem (prompt managers, plugins worth installing).
Overview for the language-level
use/exportsemantics.