Skip to content
@bashmgmt

bashmgmt

bashmgmt

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

Where to start

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

Repositories

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.

Popular repositories Loading

  1. bash-strings bash-strings Public

    Parse and emit bash's own quoted value forms: @Q words, array literals, declare -p bodies, and a word lexer over bash quoting.

    Rust

  2. bash-interop bash-interop Public

    Run bash under instrumentation and hear what it says: a session per run, a pipe and a task per shell, words a script speaks and answers it runs.

    Rust

  3. bashcap bashcap Public

    A transparent bash wrapper that writes the full state of a running shell at every BASHCAP call site, as one JSON object per line.

    Rust

  4. bashprof bashprof Public

    Time a tree of calls in a bash program: spans travel on the wire as messages, nothing is timed or inferred in bash.

    Rust

  5. bash-interop-examples bash-interop-examples Public

    Worked rigs against the bash-interop public API, and a program a bash fixture starts for itself.

    Rust

  6. .github .github Public

    Shared CI for the bashmgmt crates

Repositories

Showing 6 of 6 repositories

Top languages

Loading…

Most used topics

Loading…