mystsh
Mystical shell parser, formatter, and interpreter with Bash support
This library provides a fast and extensible parser, formatter, and interpreter for POSIX-style shell scripts, written entirely in Rust. Inspired by mvdan/sh, but built from the ground up for performance, correctness, and hackability.
It understands real-world shell code, handles edge cases, and offers structured access to ASTs for tooling, analysis, or code transformation.
✨ Features
- ✅ Robust parser producing an abstract syntax tree (AST)
- ✅ Pretty-printer/formatter with customizable indentation
- ✅ Interpreter for executing shell scripts
- ✅ Interactive REPL mode
- ✅ Friendly, safe Rust API
🚀 Example: Parse, Format, Execute
use env;
use Error;
🔍 Parsing
#!/bin/bash
for; do
done
The parser turns this into a typed AST structure:
List:
Command: echo ["Hello, world!"]
Operator: ;
ForLoop: i in $(seq 1 10)
Command: echo ["Count: $i"]
🎨 Formatting
Messy shell script?
if [; then ; elif [; then ; else ; fi
Formatted with consistent indentation:
if [; then
elif [; then
else
fi
🧪 Interpreting
Run shell scripts programmatically (including variable handling, I/O, and exit codes):
MESSAGE="Hello from the interpreter"
Output: Hello from the interpreter Exit code: 0
💻 Interactive Mode
Launch an interactive shell with:
🔧 API
let ast = parse_script?;
let formatted = format_script;
let result = new.execute?;
🦀 Why Rust?
- Memory safety without GC
- Lightning-fast tooling
- Easy integration into other Rust projects
- Great for embedding in editors or dev tools
📦 Installation
📚 License
MIT or Apache 2.0 — your choice.