A CLI tool to inline all Rust module declarations into a single file, with optional syntax highlighting and cargo-script support. Inspired by cargo-expand.
git clone https://github.com/bilakshanp/scriptify.git
cd scriptify
cargo install --path .Or install directly from the repository:
cargo install --git https://github.com/bilakshanp/scriptify.git# unplannedInline modules and print to stdout:
scriptify src/lib.rsSave to a file:
scriptify src/lib.rs -o output.rsEnable syntax highlighting with a theme:
scriptify src/lib.rs -t monokai
scriptify src/lib.rs --theme draculaList all available themes:
scriptify --list-themesGenerate script with an empty manifest:
scriptify file.rs -eAutomatically convert a whole project into a script:
scriptify . -zNote: CWD should contain Cargo.toml file.
Generate a cargo-script (RFC 3424) with auto-discovered Cargo.toml:
scriptify src/lib.rs -z -o script.rsSpecify a custom manifest path:
scriptify src/lib.rs -m path/to/Cargo.toml -o script.rsThe generated script will have this structure:
#!/usr/bin/env -S RUSTC_BOOTSTRAP=1 RUSTFLAGS=-Coverflow-checks cargo run -qZscript --release --manifest-path
---cargo
[dependencies]
serde = "1.0"
---
// Your inlined code hereMake it executable and run:
chmod +x script.rs
./script.rsStop manifest search at current working directory:
scriptify src/lib.rs -z --stop-at-cwdGiven this structure:
src/
├── lib.rs
├── foo.rs
└── bar.rsWhere lib.rs contains:
mod foo;
mod bar;
pub fn main() {
foo::hello();
bar::world();
}Running:
scriptify src/lib.rs -o single.rsProduces a single file with all modules inlined.
Output:
mod foo {
pub fn hello();
}
mod bar {
pub fn world();
}
pub fn main() {
foo::hello();
bar::world();
}# Create a self-contained script with dependencies
scriptify src/main.rs -z > script.rs
chmod +x script.rs
# Share it with others - no cargo project needed!
./script.rs# Generate a beautifully highlighted version for review
scriptify src/lib.rs -t github-light | less -R# Modify the shebang paramaters
SCRIPTIFY_SHEBANG="#!/usr/bin/env -S cargo +nightly -zScript" scriptify file.rsRun scriptify --list-themes for the complete list.
Usage: scriptify [OPTIONS] [INPUT]
Arguments:
[INPUT] Input Rust source file
Options:
-o, --output <OUTPUT> Output file (defaults to stdout)
-t, --theme <THEME> Enable syntax highlighting with specified theme
--list-themes List all available themes
-m, --manifest <MANIFEST> Path to Cargo.toml for cargo-script generation
-z, --zscript Auto-discover Cargo.toml from input file location
--stop-at-cwd Stop searching for Cargo.toml at current working directory
-h, --help Print help
-V, --version Print version