Skip to content

pesde-pkg/croshet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

croshet

A cross-platform UNIX-like shell scripting library, developed by pesde primarily to solve the annoying rimraf problem.

Examples

Shorthand macro

Execute a singular command, or run them in bulk without much control over how:

println!(
    "singular exec result: {}, bulk exec results: {:?}",
    sh!("echo hello, croshet!").await?,
    sh!["echo $(pwd)", "mkdir hi_mom", "rm -rf hi_mom", "exit 1"].await?
);

Manual execution

Lower level API to manually run commands with full control over the options and lifecycle of the process:

// Parse the text
let list = croshet::parser::parse(&text)?;
let kill_signal = KillSignal::default();

let options = croshet::ExecuteOptionsBuilder::new()
  .args(std::env::args_os().collect())          // Args to be passed to the shell itself
  .env_vars(std::env::vars_os().collect())      // Environment variables that are set globally
  .cwd(std::env::current_dir()?)                // The working directory of the shell process
  .custom_commands(...)                         // HashMap of custom commands to be defined
  .kill_signal(kill_signal.clone())             // Pass the kill signal to control termination fo the process
  .stdin(croshet::ShellPipeReader::stdin())     // The standard input pipe
  .stdout(croshet::ShellPipeWriter::stdout())   // The standard output pipe
  .stderr(croshet::ShellPipeWriter::stderr())   // The standard error pipe
  .build()?;

// Execute!
println!("Command exited with code: {}", croshet::execute(list.clone(), options.clone()).await);

// ...Or, execute with a timeout
// Set up a separate task to cancel the execution in 5s
tokio::task::spawn(async move {
    tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
    kill_signal.send(croshet::SignalKind::SIGKILL); 
});

let exit_code = croshet::execute(list, options).await;
println!("Command exited with code: {}", exit_code);

What's with the name?

This project was initially forked from Deno's deno_task_shell, which we found a bit too boring of a name :p

Instead, we settled for the name croshet, pronounced /kroʊˈʃeɪ/ (or simply, 'crochet'), as the library "crochets together" several UNIX-y shell features (most POSIX sh and some bash features, common UNIX command line tools, etc.) with a bit of shell related flair.

About

Cross platform Unix-like shell scripting library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages