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 builtins::sched;
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 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 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 vm_helper::ShellExecutor;
pub use zshrs_daemon as daemon;
pub use ported::*;

Modules§

aot
aot submodule. 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
arith_compiler submodule. ArithCompiler — lowers zsh arithmetic expressions ($((...))) into fusevm bytecodes. Used by ZshCompiler (in compile_zsh.rs).
ast_sexp
ast_sexp submodule. Canonical AST s-expression emitter for ZshProgram.
autoload_cache
autoload_cache submodule. rkyv-backed bytecode cache for autoload functions.
bash_complete
bash_complete submodule. Rust-original types for the bash-style complete builtin extension.
canonical_apply
canonical_apply submodule. Apply daemon canonical state to a freshly-built ShellExecutor — by reading the daemon’s rkyv shard directly from disk. No IPC.
compile_zsh
compile_zsh submodule. Bytecode compiler for the ported ZshProgram AST.
compinit_bg
compinit_bg submodule. Background compinit pre-warm — extension; no zsh C counterpart.
completion
completion submodule. SQLite-backed completion engine (legacy / unused).
compsys
compsys submodule. Zsh-compatible completion system (compsys)
config
config submodule. zshrs configuration file — ~/.config/zshrs/config.toml.
daemon_presence
daemon_presence submodule. Daemon-presence detection + per-user config knob.
dap
dap submodule. DAP server for zshrs — zshrs --dap HOST:PORT.
dumpers
dumpers submodule. 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_jobs
exec_jobs submodule. Executor-side bg-job tracker. NOT a port of Src/jobs.c.
ext_builtins
ext_builtins submodule. Extension-only shell builtins (no zsh C counterpart).
extensions
extensions submodule. zshrs extensions — features zsh C does not have.
fds
fds submodule. File descriptor utilities for zshrs.
fish_features
fish_features submodule. Fish-style features for zshrs - native Rust implementations.
func_body_fmt
func_body_fmt submodule. 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_bridge submodule. fusevm bytecode-VM bridge for ShellExecutor.
fusevm_disasm
fusevm_disasm submodule. Optional fusevm bytecode listing to stdout when zshrs is invoked with --disasm.
gen_docs
gen_docs submodule. Module-doc generator — produces Markdown documentation from a parsed zshrs source file by pairing ## doc comments with the top-level function declaration immediately below them.
heredoc_ast
heredoc_ast submodule. Heredoc AST-glue types — Rust-only, NOT in zsh C.
history
history submodule. SQLite-backed command history for zshrs.
intercepts
intercepts submodule. Command intercept / advice machinery — extension; no zsh C counterpart.
log
log submodule. zshrs logging & profiling framework.
lsp
lsp submodule. LSP server for zshrs — zshrs --lsp.
lsp_symbols
lsp_symbols submodule. AST-walked symbol table for the zshrs LSP server. Powers cross-file rename and find-references with parser-validated scoping instead of the textual occurrence scan in crate::extensions::lsp::references.
overlay_snapshot
overlay_snapshot submodule. Shell-side overlay enumeration for zsync up --all.
plugin_cache
plugin_cache submodule. Plugin source cache — stores side effects of source/. in SQLite.
ported
ported submodule. 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_mod submodule. Regex module - port of Modules/regex.c
script_cache
script_cache submodule. rkyv-backed bytecode cache for zsh scripts.
stringsort
stringsort submodule. String manipulation and sorting for zshrs
vm_helper
vm_helper submodule. Shell executor state for zshrs.
worker
worker submodule. Worker pool for zshrs — persistent threads for background work.
zsh_ast
zsh_ast submodule. Zsh AST types — Rust-only, NOT in zsh C.
zsh_builtin_docs
zsh_builtin_docs submodule.
zsh_ext_builtin_docs
zsh_ext_builtin_docs submodule.
zsh_keyword_docs
zsh_keyword_docs submodule.
zsh_option_docs
zsh_option_docs submodule.
zsh_special_var_docs
zsh_special_var_docs submodule.
ztest
ztest submodule — shell-level unit test framework (port of ../strykelang test framework). ztest — shell-level unit test framework.
zwc
zwc submodule. ZWC (Zsh Word Code) file parser. Direct port of the dump-file family in zsh/Src/parse.c:3077-end.
zwc_decode
zwc_decode submodule. 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§

DPUTS
Port of #define DPUTS(X, Y) macro from Src/zsh.h:2918 (macro).
DPUTS1
Port of #define DPUTS1(X, Y, Z1) macro from Src/zsh.h:2919 (macro).
DPUTS2
Port of #define DPUTS2(X, Y, Z1, Z2) macro from Src/zsh.h:2920 (macro).
DPUTS3
Port of #define DPUTS3(X, Y, Z1, Z2, Z3) macro from Src/zsh.h:2921 (macro).
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.

Statics§

IS_ZSH_MODE
Runtime shell-mode flag set by the binary entrypoint (bins/zshrs.rs) at startup. The library can’t directly read bins/zshrs.rs::shell_mode() (it lives in the binary crate), so the binary writes this atomic when parsing --zsh / --bash / --posix and the library reads it from bridge / dispatch sites that need to gate bash-compat-vs-zsh behavior. Defaults to false (zshrs-native mode) when not explicitly set.

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.