fix positional arguments in shell command on Windows

This commit is contained in:
Nguyen Duc Toan 2023-09-22 22:50:09 +07:00 committed by sxyazi
parent b48edfd764
commit c174b01b8f
No known key found for this signature in database
3 changed files with 29 additions and 12 deletions

10
Cargo.lock generated
View file

@ -325,6 +325,15 @@ dependencies = [
"winapi", "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]] [[package]]
name = "color_quant" name = "color_quant"
version = "1.1.0" version = "1.1.0"
@ -374,6 +383,7 @@ dependencies = [
"anyhow", "anyhow",
"async-channel", "async-channel",
"clipboard-win", "clipboard-win",
"cmdexpand",
"config", "config",
"crossterm", "crossterm",
"futures", "futures",

View file

@ -30,6 +30,7 @@ yazi-prebuild = "^0"
[target.'cfg(target_os = "windows")'.dependencies] [target.'cfg(target_os = "windows")'.dependencies]
clipboard-win = "^4" clipboard-win = "^4"
cmdexpand = {git = "https://github.com/ndtoan96/cmdexpand.git", tag = "v0.1.0"}
[target.'cfg(not(target_os = "netbsd"))'.dependencies] [target.'cfg(not(target_os = "netbsd"))'.dependencies]
trash = "^3" trash = "^3"

View file

@ -43,16 +43,22 @@ pub fn shell(opt: ShellOpt) -> Result<Child> {
.spawn()?, .spawn()?,
); );
#[cfg(windows)] #[cfg(target_os = "windows")]
return Ok( {
Command::new("cmd") let args: Vec<String> = opt.args.iter().map(|s| s.to_string_lossy().to_string()).collect();
.stdin(opt.stdio()) let cmd = cmdexpand::Expander::new(&opt.cmd.to_string_lossy().to_string())
.stdout(opt.stdio()) .disable_context(true)
.stderr(opt.stdio()) .add_args(&args)
.arg("/C") .expand()?;
.arg(opt.cmd) Ok(
.args(opt.args) Command::new("cmd")
.kill_on_drop(true) .arg("/C")
.spawn()?, .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()?,
)
}
} }