diff --git a/Cargo.lock b/Cargo.lock index 9a6f1fbe..e9c891ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -325,6 +325,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "cmdexpand" +version = "0.1.0" +source = "git+https://github.com/ndtoan96/cmdexpand.git?tag=v0.1.0#be905e223c7ed5f52655fb4096c842f2f587f0d7" +dependencies = [ + "nom", + "thiserror", +] + [[package]] name = "color_quant" version = "1.1.0" @@ -374,6 +383,7 @@ dependencies = [ "anyhow", "async-channel", "clipboard-win", + "cmdexpand", "config", "crossterm", "futures", diff --git a/core/Cargo.toml b/core/Cargo.toml index b9c0d862..3a472123 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -30,6 +30,7 @@ yazi-prebuild = "^0" [target.'cfg(target_os = "windows")'.dependencies] clipboard-win = "^4" +cmdexpand = {git = "https://github.com/ndtoan96/cmdexpand.git", tag = "v0.1.0"} [target.'cfg(not(target_os = "netbsd"))'.dependencies] trash = "^3" diff --git a/core/src/external/shell.rs b/core/src/external/shell.rs index 4285c7a7..10c5709f 100644 --- a/core/src/external/shell.rs +++ b/core/src/external/shell.rs @@ -43,16 +43,22 @@ pub fn shell(opt: ShellOpt) -> Result { .spawn()?, ); - #[cfg(windows)] - return Ok( - Command::new("cmd") - .stdin(opt.stdio()) - .stdout(opt.stdio()) - .stderr(opt.stdio()) - .arg("/C") - .arg(opt.cmd) - .args(opt.args) - .kill_on_drop(true) - .spawn()?, - ); + #[cfg(target_os = "windows")] + { + let args: Vec = opt.args.iter().map(|s| s.to_string_lossy().to_string()).collect(); + let cmd = cmdexpand::Expander::new(&opt.cmd.to_string_lossy().to_string()) + .disable_context(true) + .add_args(&args) + .expand()?; + Ok( + Command::new("cmd") + .arg("/C") + .arg(cmd) + .stdin(if opt.piped { Stdio::piped() } else { Stdio::inherit() }) + .stdout(if opt.piped { Stdio::piped() } else { Stdio::inherit() }) + .stderr(if opt.piped { Stdio::piped() } else { Stdio::inherit() }) + .kill_on_drop(true) + .spawn()?, + ) + } }