coliru

A minimal, flexible, dotfile installer
git clone https://git.ashermorgan.net/coliru/
Log | Files | Refs | README

commit 864b32cdb374b8d0f3dad687b3da72960d2f336b
parent a212f1ca51ef3c9dddc52f46392e06c4e8fb5374
Author: Asher Morgan <59518073+ashermorgan@users.noreply.github.com>
Date:   Fri, 21 Jun 2024 19:10:46 -0700

Implement run command prefix option

Diffstat:
Msrc/core.rs | 2+-
Msrc/manifest.rs | 4++++
Msrc/utils.rs | 8++++----
3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/core.rs b/src/core.rs @@ -82,7 +82,7 @@ fn execute_runs(runs: &[RunOptions], dry_run: bool) { } println!(""); - if let Err(why) = run_script(&run.src) { + if let Err(why) = run_script(&run.src, &run.prefix) { eprintln!(" Error: {}", why); } } diff --git a/src/manifest.rs b/src/manifest.rs @@ -12,6 +12,9 @@ pub struct CopyLinkOptions { #[derive(Debug, PartialEq, Deserialize)] pub struct RunOptions { pub src: String, + + #[serde(default)] + pub prefix: String, } #[derive(Debug, PartialEq, Deserialize)] @@ -102,6 +105,7 @@ mod tests { run: vec![ RunOptions { src: String::from("baz"), + prefix: String::from(""), }, ], tags: vec![String::from("c")], diff --git a/src/utils.rs b/src/utils.rs @@ -48,21 +48,21 @@ fn prepare_path(path: &str) -> Result<PathBuf> { Ok(_dst) } -/// Execute a local shell script. +/// Execute a local shell script, optionally with a command prefix. /// /// Uses sh on Unix and PowerShell on Windows. -pub fn run_script(path: &str) -> Result<()> { +pub fn run_script(path: &str, prefix: &str) -> Result<()> { if cfg!(target_family = "unix") { Command::new("sh") .arg("-c") - .arg(fs::canonicalize(path)?) + .arg(format!("{} {}", prefix, fs::canonicalize(path)?.display())) .status()?; } else { // Use absolute() instead of canonicalize() to avoid incompatible paths: // https://github.com/rust-lang/rust/issues/42869 Command::new("powershell") .args(["-ExecutionPolicy", "Bypass", "-Command"]) - .arg(absolute(path)?) + .arg(format!("{} {}", prefix, absolute(path)?.display())) .status()?; } Ok(())