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",
]
[[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",

View file

@ -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"

View file

@ -43,16 +43,22 @@ pub fn shell(opt: ShellOpt) -> Result<Child> {
.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<String> = 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()?,
)
}
}