btl

Crates.iobtl
lib.rsbtl
version0.3.0
sourcesrc
created_at2021-01-25 06:56:51.025791
updated_at2021-04-06 01:09:02.347467
descriptionSimple shell scripting in rust. Github Repo: https://github.com/znx3p0/btlsh
homepage
repositoryhttps://github.com/znx3p0/btlsh
max_upload_size
id346326
size8,431
(znx3p0)

documentation

https://docs.rs/btl/

README

Btl

docs

Btl is a simple library that makes shell scripting with rust easier. It was originally written with the purposes of being used for build.rs files, but it can be used for more complex purposes.

It's main premise is about integrating shell scripting with rust ergonomically. This works both on windows and unix machines.

Btl is extremely simple, composed of six macros which have the exact same syntax. These macros allows for embedding shell scripts to rust while allowing extreme customization ergonomically.

Macros:

  • shell!{}
  • detach!{}
  • execute!{}
  • exec!{}
  • cd!{}

support for tokio is under the "tokio_shell" feature, and they have the same syntax and names, but they have the "async_" prefix.

NOTE: btl uses sh as the unix backend, and powershell as the windows backend.

If you happen to find any bug, please raise an issue at the github repo.

Example:

fn shell() -> Result<(), std::io::Error> {
    // all macros use the try operator to avoid unwrapping
    // creates a detached process that may outlive the current process
    detach! {
        "touch m.txt";
        "sleep {}", 10;
        "rm m.txt";
    };

    // changes directory
    cd!("..").unwrap();
    let contents = execute! {
        "ls";
    };
    // returns a string containing the stdout of the process
    println!("contents {:?}", contents);

    // returns a bool indicating if the operation was successful
    if exec! {
        "ls";
    } {
        println!("success")
    } else {
        println!("not successful")
    }

    shell! {
        "ls {}", "-la";
    };

    Ok(())
}
Commit count: 34

cargo fmt