#shell #xshell #xshell-macros

macro xshell-macros

Private implementation detail of xshell crate

28 releases

0.3.0-pre.2 Dec 23, 2024
0.2.7 Nov 16, 2024
0.2.6 Mar 28, 2024
0.2.5 Jul 11, 2023
0.1.6 Oct 19, 2020

#1666 in Procedural macros

Download history 84766/week @ 2024-12-09 75822/week @ 2024-12-16 36116/week @ 2024-12-23 48137/week @ 2024-12-30 81170/week @ 2025-01-06 84211/week @ 2025-01-13 81420/week @ 2025-01-20 91706/week @ 2025-01-27 97711/week @ 2025-02-03 102159/week @ 2025-02-10 91902/week @ 2025-02-17 96358/week @ 2025-02-24 103050/week @ 2025-03-03 117855/week @ 2025-03-10 123080/week @ 2025-03-17 105991/week @ 2025-03-24

457,245 downloads per month
Used in 168 crates (via xshell)

MIT/Apache

8KB
194 lines

xshell: Making Rust a Better Bash

xshell provides a set of cross-platform utilities for writing cross-platform and ergonomic "bash" scripts.

Example

//! Clones a git repository and publishes it to crates.io.
use xshell::{cmd, Shell};

fn main() -> anyhow::Result<()> {
    let sh = Shell::new()?;

    let user = "matklad";
    let repo = "xshell";
    cmd!(sh, "git clone https://github.com/{user}/{repo}.git").run_echo()?;
    sh.set_current_dir(repo);

    let test_args = ["-Zunstable-options", "--report-time"];
    cmd!(sh, "cargo test -- {test_args...}").run_echo()?;

    let manifest = sh.read_file("Cargo.toml")?;
    let version = manifest
        .split_once("version = \"")
        .and_then(|it| it.1.split_once('\"'))
        .map(|it| it.0)
        .ok_or_else(|| anyhow::format_err!("can't find version field in the manifest"))?;

    cmd!(sh, "git tag {version}").run_echo()?;

    let dry_run = if sh.var("CI").is_ok() { None } else { Some("--dry-run") };
    cmd!(sh, "cargo publish {dry_run...}").run_echo()?;

    Ok(())
}

See the docs for more.

If you like the ideas behind xshell, you will enjoy dax.

No runtime deps