|
1 | 1 | use std::{ffi::OsString, process::Stdio}; |
2 | 2 |
|
3 | 3 | use anyhow::Result; |
4 | | -use tokio::process::{Child, Command}; |
| 4 | +use tokio::{process::{Child, Command}, task}; |
5 | 5 | use yazi_fs::Cwd; |
6 | 6 | use yazi_macro::impl_data_any; |
7 | 7 | use yazi_shared::url::{AsUrl, UrlBuf}; |
@@ -30,42 +30,40 @@ impl ShellOpt { |
30 | 30 | } |
31 | 31 |
|
32 | 32 | pub(crate) async fn shell(opt: ShellOpt) -> Result<Child> { |
33 | | - tokio::task::spawn_blocking(move || { |
34 | | - let cwd = Cwd::ensure(opt.cwd.as_url()); |
| 33 | + let (cwd, opt) = |
| 34 | + task::spawn_blocking(move || (Cwd::ensure(opt.cwd.as_url()).into_owned(), opt)).await?; |
35 | 35 |
|
36 | | - #[cfg(unix)] |
37 | | - return Ok(unsafe { |
38 | | - Command::new("sh") |
39 | | - .stdin(opt.stdio()) |
40 | | - .stdout(opt.stdio()) |
41 | | - .stderr(opt.stdio()) |
42 | | - .arg("-c") |
43 | | - .arg(opt.cmd) |
44 | | - .current_dir(cwd) |
45 | | - .kill_on_drop(!opt.orphan) |
46 | | - .pre_exec(move || { |
47 | | - if !opt.block && libc::setsid() < 0 { |
48 | | - return Err(std::io::Error::last_os_error()); |
49 | | - } |
50 | | - Ok(()) |
51 | | - }) |
52 | | - .spawn()? |
53 | | - }); |
| 36 | + #[cfg(unix)] |
| 37 | + return Ok(unsafe { |
| 38 | + Command::new("sh") |
| 39 | + .stdin(opt.stdio()) |
| 40 | + .stdout(opt.stdio()) |
| 41 | + .stderr(opt.stdio()) |
| 42 | + .arg("-c") |
| 43 | + .arg(opt.cmd) |
| 44 | + .current_dir(cwd) |
| 45 | + .kill_on_drop(!opt.orphan) |
| 46 | + .pre_exec(move || { |
| 47 | + if !opt.block && libc::setsid() < 0 { |
| 48 | + return Err(std::io::Error::last_os_error()); |
| 49 | + } |
| 50 | + Ok(()) |
| 51 | + }) |
| 52 | + .spawn()? |
| 53 | + }); |
54 | 54 |
|
55 | | - #[cfg(windows)] |
56 | | - return Ok( |
57 | | - Command::new("cmd.exe") |
58 | | - .stdin(opt.stdio()) |
59 | | - .stdout(opt.stdio()) |
60 | | - .stderr(opt.stdio()) |
61 | | - .env("=", r#""^\n\n""#) |
62 | | - .raw_arg(r#"/Q /S /D /V:OFF /E:ON /C ""#) |
63 | | - .raw_arg(opt.cmd) |
64 | | - .raw_arg(r#"""#) |
65 | | - .current_dir(cwd) |
66 | | - .kill_on_drop(!opt.orphan) |
67 | | - .spawn()?, |
68 | | - ); |
69 | | - }) |
70 | | - .await? |
| 55 | + #[cfg(windows)] |
| 56 | + return Ok( |
| 57 | + Command::new("cmd.exe") |
| 58 | + .stdin(opt.stdio()) |
| 59 | + .stdout(opt.stdio()) |
| 60 | + .stderr(opt.stdio()) |
| 61 | + .env("=", r#""^\n\n""#) |
| 62 | + .raw_arg(r#"/Q /S /D /V:OFF /E:ON /C ""#) |
| 63 | + .raw_arg(opt.cmd) |
| 64 | + .raw_arg(r#"""#) |
| 65 | + .current_dir(cwd) |
| 66 | + .kill_on_drop(!opt.orphan) |
| 67 | + .spawn()?, |
| 68 | + ); |
71 | 69 | } |
0 commit comments