Crates.io | btl |
lib.rs | btl |
version | 0.3.0 |
source | src |
created_at | 2021-01-25 06:56:51.025791 |
updated_at | 2021-04-06 01:09:02.347467 |
description | Simple shell scripting in rust. Github Repo: https://github.com/znx3p0/btlsh |
homepage | |
repository | https://github.com/znx3p0/btlsh |
max_upload_size | |
id | 346326 |
size | 8,431 |
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:
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(())
}