Skip to main content

Crate zsh

Crate zsh 

Source
Expand description

Zsh interpreter and parser in Rust

This crate provides:

  • A complete zsh lexer (lexer module)
  • A zsh parser (parser module)
  • Shell execution engine (exec module)
  • Job control (jobs module)
  • History management (history module)
  • ZLE (Zsh Line Editor) support (zle module)
  • ZWC (compiled zsh) support (zwc module)
  • Fish-style features (fish_features module)
  • Mathematical expression evaluation (math module)

Re-exports§

pub use ported::lex;
pub use ported::lex as tokens;
pub use ported::parse;
pub use modules::attr;
pub use modules::cap;
pub use modules::clone;
pub use modules::curses;
pub use modules::datetime;
pub use modules::db_gdbm;
pub use modules::example;
pub use modules::files;
pub use modules::hlgroup;
pub use modules::ksh93;
pub use modules::langinfo;
pub use modules::mapfile;
pub use modules::mathfunc;
pub use modules::nearcolor;
pub use modules::newuser;
pub use modules::param_private;
pub use modules::parameter;
pub use modules::pcre;
pub use modules::random;
pub use modules::random_real;
pub use modules::regex as regex_module;
pub use builtins::sched;
pub use modules::socket;
pub use modules::stat;
pub use modules::system;
pub use modules::tcp;
pub use modules::termcap;
pub use modules::terminfo;
pub use modules::watch;
pub use modules::zftp;
pub use modules::zprof;
pub use modules::zpty;
pub use modules::zselect;
pub use modules::zutil;
pub use builtins::rlimits;
pub use exec::ShellExecutor;
pub use fish_features::autosuggest_from_history;
pub use fish_features::colorize_line;
pub use fish_features::expand_abbreviation;
pub use fish_features::highlight_shell;
pub use fish_features::is_private_mode;
pub use fish_features::kill_add;
pub use fish_features::kill_replace;
pub use fish_features::kill_yank;
pub use fish_features::kill_yank_rotate;
pub use fish_features::set_private_mode;
pub use fish_features::validate_autosuggestion;
pub use fish_features::validate_command;
pub use fish_features::with_abbrs;
pub use fish_features::with_abbrs_mut;
pub use fish_features::AbbrPosition;
pub use fish_features::Abbreviation;
pub use fish_features::AbbreviationSet;
pub use fish_features::Autosuggestion;
pub use fish_features::HighlightRole;
pub use fish_features::HighlightSpec;
pub use fish_features::KillRing;
pub use fish_features::ValidationStatus;
pub use tokens::lextok;
pub use zshrs_daemon as daemon;
pub use ported::*;

Modules§

aot
Ahead-of-time build: bake one or more shell scripts into a copy of the running zshrs binary as a compressed trailer, producing a self-contained executable. At startup, zshrs detects the trailer and runs every embedded script IN INPUT ORDER as a single concatenated zsh program.
arith_compiler
ArithCompiler — lowers zsh arithmetic expressions ($((...))) into fusevm bytecodes. Used by ZshCompiler (in compile_zsh.rs).
ast_sexp
Canonical AST s-expression emitter for ZshProgram.
autoload_cache
rkyv-backed bytecode cache for autoload functions.
bash_complete
Rust-original types for the bash-style complete builtin extension.
canonical_apply
Apply daemon canonical state to a freshly-built ShellExecutor — by reading the daemon’s rkyv shard directly from disk. No IPC.
compile_zsh
Bytecode compiler for the ported ZshProgram AST.
compinit_bg
Background compinit pre-warm — extension; no zsh C counterpart.
completion
SQLite-backed completion engine for zshrs
config
zshrs configuration file — ~/.config/zshrs/config.toml.
daemon_presence
Daemon-presence detection + per-user config knob.
dap
DAP server for zshrs — zshrs --dap HOST:PORT.
dumpers
Source-to-IR dumpers exposed to the zshrs CLI as --dump-tokens, --dump-ast, --dump-wordcode. Same logic as examples/{lex,ast,parse}_dump.rs and the parity harnesses (tests/lexer_parity.rs, tests/parity_harness.rs, tests/wordcode_parity.rs) — keeping them in one library function per IR so the binary, examples, and tests can all share output format.
exec
Shell executor state for zshrs.
exec_jobs
Executor-side bg-job tracker. NOT a port of Src/jobs.c.
ext_builtins
Extension-only shell builtins (no zsh C counterpart).
extensions
zshrs extensions — features zsh C does not have.
fds
File descriptor utilities for zshrs.
fish_features
Fish-style features for zshrs - native Rust implementations.
func_body_fmt
Non-C helper: format raw function-body source the way zsh typeset -f presents multi-statement bodies (split on top-level ; / newlines).
fusevm_bridge
fusevm bytecode-VM bridge for ShellExecutor.
fusevm_disasm
Optional fusevm bytecode listing to stdout when zshrs is invoked with --disasm.
heredoc_ast
Heredoc AST-glue types — Rust-only, NOT in zsh C.
history
SQLite-backed command history for zshrs.
intercepts
Command intercept / advice machinery — extension; no zsh C counterpart.
log
zshrs logging & profiling framework.
lsp
LSP server for zshrs — zshrs --lsp.
overlay_snapshot
Shell-side overlay enumeration for zsync up --all.
plugin_cache
Plugin source cache — stores side effects of source/. in SQLite.
ported
Ported subsystems — every submodule here is a faithful 1:1 port of a corresponding upstream zsh C source file under src/zsh/Src/.
regex_mod
Regex module - port of Modules/regex.c
script_cache
rkyv-backed bytecode cache for zsh scripts.
stringsort
String manipulation and sorting for zshrs
worker
Worker pool for zshrs — persistent threads for background work.
zsh_ast
Zsh AST types — Rust-only, NOT in zsh C.
zwc
ZWC (Zsh Word Code) file parser. Direct port of the dump-file family in zsh/Src/parse.c:3077-end.
zwc_decode
Recursive wordcode walker — decodes a .zwc blob into the parser’s own ZshProgram AST so the parity harness can compare zsh-side and zshrs-side ASTs through a single sexp emitter (ast_sexp).

Macros§

ERRMSG
Port of #define ERRMSG(x) from Src/zsh.h:2917. Build a debug error-message prefix __FILE__ ":" __LINE__ ": " x.
HEAP_ERROR
Port of #define HEAP_ERROR(heap_id) from Src/zsh.h:2864. Debug- only macro that fprintf’s an “invalid heap” error to stderr. Rust port: eprintln! with the same format. Only active under the zsh-heap-debug feature.
STRINGIFY
Port of #define STRINGIFY(x) from Src/zsh.h:2916. Two-pass stringification (expand x first, then stringify).
STRINGIFY_LITERAL
Port of #define STRINGIFY_LITERAL(x) from Src/zsh.h:2915. C uses the # operator to stringify an identifier. Rust’s stringify! macro does the same.

Functions§

set_stryke_handler
Register a handler for @ prefix lines (fat binary sets this to stryke::run).
try_stryke_dispatch
Try to dispatch a line starting with @ to stryke. Returns Some(exit_code) if handled, None if no handler registered.