DEV Community

hinika
hinika

Posted on

Wisp 3.2: A 3.3k-line Linux shell with Lua 5.4 and structured pipelines

I just released wisp 3.2.0 — a small Linux shell written in ~3,350 lines of C++17 with Lua 5.4 embedded for config, scripting, and structured pipelines.

wisp demo

Repo: https://github.com/Hinikaa/wisp

Why Lua in a shell?

Traditional shells are great interactively, right up until you have to write config, aliases, or parse command output across a pipeline. Instead of inventing a new scripting language, wisp embeds Lua 5.4 directly:

  • Any global function in ~/.config/wisp/init.lua automatically becomes a shell command.
  • Consecutive Lua stages in a pipeline run in-process on the Lua stack, passing real Lua tables from one stage to the next without forking or converting to text.
  • When a pipeline crosses into an external binary (grep, wc, etc.) or redirects to a file, wisp serializes tables into plain key=value lines automatically. When outputting to a terminal, it renders aligned columns.

Structured pipelines out of the box

v3.2 ships with a small built-in prelude (files, where, sort_by, cols, take, skip, count, lines, to_json), so you can try structured pipelines with zero config:

wisp> files | where name ~= %.cpp$ | sort_by size desc | take 5 | cols name size
name             size
──────────────  ─────
executor.cpp    52770
lua_env.cpp     25926
main.cpp        14378
lexer.cpp        5836
test_lexer.cpp   5028

wisp> files | where name == main.cpp | cols name type size | to_json
[{"name":"main.cpp","size":14378,"type":"file"}]
Enter fullscreen mode Exit fullscreen mode

Regular interactive shell features are all there too: real job control (Ctrl-Z, fg, bg, jobs, kill %N, disown, wait), redirects (<, >, >>, 2>, 2>&1, &>), globs, brace expansion ({a,b}{1..3}), $(cmd), Ctrl-R history search, inline history autosuggestions (Right arrow to accept), post-pipe tab completion, and typo hints (grpe -> did you mean 'grep'?).

A few interesting bits under the hood

  • Per-character quote masks: The lexer tracks quoting per character (0 bare, 1 single-quoted/escaped, 2 double-quoted) rather than per word, so --format='%h %s' stays one argument and "$HOME" expands variables without triggering globbing or brace expansion.
  • No-deadlock builtin pipes: When a builtin feeds a downstream command, output is captured into a temp file instead of an OS pipe so anything over 64KB won't block before the reader starts.
  • Interruptible Lua (Ctrl-C): Long-running in-process Lua stages arm a SIGINT + lua_sethook guard (same technique as standalone lua.c) so Ctrl-C stops a runaway script without killing the shell.
  • Three-layer tests: Unit tests (lexer/parser/executor/Lua boundary), end-to-end shell tests (test_shell.sh), and a Python PTY harness (test_interactive.py) exercising real terminal job control.

Try it out

Arch Linux (AUR):

yay -S wisp-shell
Enter fullscreen mode Exit fullscreen mode

Nix / NixOS (zero-install):

nix run github:Hinikaa/wisp
Enter fullscreen mode Exit fullscreen mode

Any Linux (x86_64 / aarch64, Lua 5.4 statically linked):

curl -fsSL https://raw.githubusercontent.com/Hinikaa/wisp/master/install.sh | sh
Enter fullscreen mode Exit fullscreen mode

(Full disclosure: I used AI to help write the C++ parts since C++ isn't my strongest language, while steering the design, testing, and debugging myself.)

Source & docs: https://github.com/Hinikaa/wisp

Top comments (2)

Collapse
 
userxnom profile image
Abdullah Naseer •

The design decision that sold me is the one in the middle: consecutive Lua stages run in-process passing real tables, and only when a stage crosses into an external binary does it serialize to key=value lines. That's the whole structured-pipeline idea done honestly — no pretending text isn't there, just choosing exactly where the boundary is. And the under-the-hood details are the kind you only write after hitting the bugs yourself: per-character quote masks so --format='%h %s' stays one argument, temp files instead of OS pipes so a builtin feeding a downstream command can't deadlock, and the SIGINT + lua_sethook guard so Ctrl-C stops a runaway script without killing the shell. One question: the 'grpe -> did you mean grep?' correction — is that a fixed suggestion list, or does it learn from the commands you actually use over time?

Collapse
 
hinika profile image
hinika •

Thanks a lot, glad those details stood out! Those bugs really did all show up the hard way (especially the PTY/Ctrl-C and builtin pipe ones).

For the typo hint, it's neither a hardcoded list nor learned from history right now — it scans the cached list of executables on your actual $PATH (the same cache tab completion and type share, refreshed automatically if PATH changes) and runs a bounded Damerau-Levenshtein edit distance check (threshold 3). Counting an adjacent character swap as a single edit instead of two is what makes grpe land cleanly on grep instead of tying with unrelated 4-letter commands.

Weighting ties by command history — and including builtins + Lua functions from init.lua in the candidate pool — is actually a great idea though, definitely worth adding next!