rmux_client/commands/
scripting.rs1use rmux_proto::{
2 IfShellRequest, Request, Response, RunShellDelaySeconds, RunShellRequest, Target, WaitForMode,
3 WaitForRequest,
4};
5use std::path::PathBuf;
6
7use crate::{connection::Connection, ClientError};
8
9impl Connection {
10 #[allow(clippy::too_many_arguments)]
13 pub fn run_shell(
14 &mut self,
15 command: String,
16 background: bool,
17 as_commands: bool,
18 show_stderr: bool,
19 delay_seconds: Option<f64>,
20 start_directory: Option<PathBuf>,
21 target: Option<rmux_proto::PaneTarget>,
22 ) -> Result<Response, ClientError> {
23 self.roundtrip_without_read_timeout(&Request::RunShell(RunShellRequest {
24 command,
25 background,
26 as_commands,
27 show_stderr,
28 delay_seconds: delay_seconds.map(RunShellDelaySeconds),
29 start_directory,
30 target,
31 }))
32 }
33
34 pub fn if_shell(
37 &mut self,
38 condition: String,
39 format_mode: bool,
40 then_command: String,
41 else_command: Option<String>,
42 target: Option<Target>,
43 background: bool,
44 ) -> Result<Response, ClientError> {
45 self.roundtrip_without_read_timeout(&Request::IfShell(IfShellRequest {
46 condition,
47 format_mode,
48 then_command,
49 else_command,
50 target,
51 caller_cwd: current_working_directory(),
52 background,
53 }))
54 }
55
56 pub fn wait_for(
59 &mut self,
60 channel: String,
61 mode: WaitForMode,
62 ) -> Result<Response, ClientError> {
63 self.roundtrip_without_read_timeout(&Request::WaitFor(WaitForRequest { channel, mode }))
64 }
65}
66
67fn current_working_directory() -> Option<PathBuf> {
68 std::env::current_dir().ok()
69}