The crates in this organisation let a Rust program run a bash program, hear every shell in its process tree, and answer the questions those shells ask. The script states what it wants observed at one-line call sites, and the Rust side receives each statement as a message. Nothing is parsed out of a set -x trace, and the program behaves as it does when nothing is listening.
bash-interop is the library at the centre. A script that has joined a session ships a list of words with BC_SAY and carries on, or ships one with BC_ASK and waits for the reply. The reply is a command, and the shell that asked runs it in the frame that asked. An answer can therefore print a value for x=$(BC_ASK), bind a variable in the caller's scope, set the status an if branches on, or return from the calling function. Every bash process that joins gets a pipe and a task of its own on the Rust side, which keeps a subshell apart from its parent, and each message carries the sending shell's clock and its view of the call stack.
bashcap and bashprof are two command-line tools built on that library, and they read as examples of it. bashcap writes what a shell held at each marked point as one JSON object per line, with the call stack and the named variables, where an array stays an array and an associative array keeps its keys. bashprof times a tree of calls. A script wraps a command with a label, and the report nests the calls made in subshells under their parents and shows each call's own time beside its total.
bash-strings sits underneath. Bash has a serialisation format of its own, the one that printf %q, ${var@Q} and declare -p write and that declare -a arr="$word" reads back. The crate parses and emits that format in Rust, and every line bash-interop puts on the wire is written in it.
bashcap bashprof the tools: run a script under capture or timing
\ /
bash-interop sessions, rigs, the wire
|
bash-strings bash's quoted value forms
| You want to | Start here |
|---|---|
| time the steps of a bash program | cargo install bashprof, then the bashprof README |
| see what a shell held at some point | cargo install bashcap, then the bashcap README |
| write a tool of your own | the overview in the bash-interop book, then the worked examples |
| read or write bash's quoted values in Rust | the reference of bash-strings |
| Repository | What it holds | Book | Crate |
|---|---|---|---|
bash-interop |
the library: sessions, rigs, joining, the wire | book | crates.io |
bashcap |
the tool that records the state of a shell at marked call sites | book | crates.io |
bashprof |
the tool that times a tree of calls | book | crates.io |
bash-strings |
the codec for bash's quoted value forms | book | crates.io |
bash-interop-examples |
complete programs against the public API of bash-interop, each one a test that runs | ||
.github |
the CI and book workflows the crates share |
All crates are under the MIT licence.
The organisation is named after bashmgmt, a module system for bash. These crates are its first public parts.