#shell #env

build xshell

Utilities for quick shell scripting in Rust

23 releases

0.2.5 Jul 11, 2023
0.2.3 Dec 14, 2022
0.2.2 Jun 8, 2022
0.2.1 Mar 16, 2022
0.1.6 Oct 19, 2020

#30 in Filesystem

Download history 36867/week @ 2023-08-15 37908/week @ 2023-08-22 35337/week @ 2023-08-29 35660/week @ 2023-09-05 32694/week @ 2023-09-12 34010/week @ 2023-09-19 35588/week @ 2023-09-26 38431/week @ 2023-10-03 38177/week @ 2023-10-10 44045/week @ 2023-10-17 45686/week @ 2023-10-24 44426/week @ 2023-10-31 46540/week @ 2023-11-07 53174/week @ 2023-11-14 43987/week @ 2023-11-21 40620/week @ 2023-11-28

191,810 downloads per month
Used in 87 crates (26 directly)

MIT/Apache

47KB
716 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()?;
    sh.change_dir(repo);

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

    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()?;

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

    Ok(())
}

See the docs for more.

Dependencies