Nelua

nebox · the shell

nsh

A POSIX shell to live in, written in Nelua all the way down to the C library.

nsh is the interactive side of nebox's sh: the same POSIX command language, checked against dash case by case, with a line editor, history, completion and a prompt built for everyday use. It is one applet of a static x86-64 binary that links no host libc at all; everything under it, down to tcgetattr and setjmp, is nelibc.

444 POSIX cases against dash24 pseudo-terminal sessions1,788,432 bytes for all 89 appletsnm -u emptyrecorded 2026-11-07

Shell startup and catalog processing

On 21 November 2026 a fresh Nebox shell printed 42 in 0.49 ms versus 0.71 ms for Debian dash. Reading the 439-line BusyBox applet catalog with shell builtins and counting its five sha-prefixed names took 14.77 ms versus 7.27 ms. Both figures are medians of 12 interleaved rounds on the same i5-10400.

A session

A replay of a real nsh session, recorded on a pseudo-terminal from the build that the tests ran on (only the home directory's path is shortened to /home/demo). Keys pressed are shown as chips.

nsh — /home/demo

What it does

The line editor

Its own editor, in Nelua: lines that wrap past the terminal width redraw correctly, the cursor moves by UTF-8 character, consecutive kills join into one entry as in readline, and pasted text arrives whole through bracketed paste instead of being run line by line.

History

Every command, multi-line ones included, goes to ~/.local/state/nsh/history (or $HISTFILE) as it runs, so a crash loses nothing. Up and Down walk it; Ctrl-R searches it incrementally. A line equal to the one before, or starting with a space, is not kept.

Completion

Tab completes commands in command position (built-ins, functions, aliases, reserved words and everything on PATH), file names elsewhere (with ~, directories ending in /, special characters escaped) and $NAMEs. A second Tab lists the candidates in columns.

Mistakes don't end the session

A syntax error, a failed expansion such as ${x?}, or an error in a special built-in returns to the prompt with status 2, as POSIX requires of an interactive shell. Ctrl-C ends what is being typed or run; SIGTERM and SIGQUIT are ignored by the shell, never by its children.

Prompts that compute

PS1 gets parameter, command and arithmetic expansion before each prompt, then ! becomes the history number. The default shows the directory's name in colour, ~ at home, and # for root. PS2 marks continuation lines and here-documents.

Job control

Every pipeline gets its own process group and the foreground one owns the terminal. Ctrl-Z stops it and hands the terminal back with the shell's own modes; fg restores the job's modes and continues it, bg lets it run behind you, and jobs, kill %1 and wait %vim name jobs by number, prefix or substring. Finished background jobs are reported before the next prompt, and leaving with stopped jobs warns first.

The whole POSIX language

Pipelines, lists, subshells, functions, case and loops, every redirection and here-document form, aliases, all parameter expansions, command substitution, 64-bit arithmetic, traps, set -e and the special and regular built-ins, compared with dash 0.5.12 in 444 cases.

Keys

Redraw accounts for wide characters and combining marks. Cursor motion follows Unicode code points.

Ctrl-A, Ctrl-E, Home, End
start and end of the line
Ctrl-B, Ctrl-F, ←, →
back and forward a character
Alt-B, Alt-F, Ctrl-←, Ctrl-→
back and forward a word
Ctrl-K, Ctrl-U, Ctrl-W, Alt-D, Alt-Backspace
kill to the end, to the start, the previous blank-separated word, the next word, the previous word
Ctrl-Y
yank the last kill
Ctrl-T
transpose characters
Ctrl-P, Ctrl-N, ↑, ↓
previous and next history entry
Ctrl-R
incremental reverse search; Ctrl-R again for older matches, Enter runs, Ctrl-G cancels
Tab
complete; a second Tab lists the candidates
Ctrl-L
clear the screen
Ctrl-C, Ctrl-D
discard the line; exit on an empty line
Ctrl-Z
stop the foreground job; fg and bg continue it

Resource limits

Run ulimit -Sn to show the soft open-file limit, ulimit -Hn to show the hard limit, or ulimit -a to see all limits. Changes apply to the current shell and its children.

Install

git clone https://github.com/Spaceghost/nelibc
make -C nelibc lib-standalone-zig
git clone https://github.com/Spaceghost/nebox
make -C nebox NELIBC=../nelibc           # build/nebox, one static binary
ln -s "$PWD/nebox/build/nebox" ~/.local/bin/nsh
nsh

Configuration goes in ~/.config/nsh/rc (run at startup as ENV; plain shell). sh -i is the same shell with POSIX defaults: PS1='$ ' and ~/.sh_history.

History and vi editing

  • fc -l lists command history. fc -s recalls a command by number or prefix, with optional text substitution. fc -e opens selected commands in an editor and runs the edited text.
  • set -o vi enables vi editing. Press Escape for command mode. Move, recall history, delete, change, yank, put or undo. set -o emacs restores Emacs keys.