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 arguments: Vec<String>,
17 background: bool,
18 as_commands: bool,
19 show_stderr: bool,
20 delay_seconds: Option<f64>,
21 start_directory: Option<PathBuf>,
22 target: Option<rmux_proto::PaneTarget>,
23 ) -> Result<Response, ClientError> {
24 self.roundtrip_without_read_timeout(&Request::RunShell(Box::new(RunShellRequest {
25 command,
26 arguments,
27 background,
28 as_commands,
29 show_stderr,
30 delay_seconds: delay_seconds.map(RunShellDelaySeconds),
31 start_directory,
32 target,
33 source_depth: None,
34 })))
35 }
36
37 pub fn if_shell(
40 &mut self,
41 condition: String,
42 format_mode: bool,
43 then_command: String,
44 else_command: Option<String>,
45 target: Option<Target>,
46 background: bool,
47 ) -> Result<Response, ClientError> {
48 self.roundtrip_without_read_timeout(&Request::IfShell(Box::new(IfShellRequest {
49 condition,
50 format_mode,
51 then_command,
52 else_command,
53 target,
54 caller_cwd: current_working_directory(),
55 background,
56 })))
57 }
58
59 pub fn wait_for(
62 &mut self,
63 channel: String,
64 mode: WaitForMode,
65 ) -> Result<Response, ClientError> {
66 self.roundtrip_without_read_timeout(&Request::WaitFor(WaitForRequest { channel, mode }))
67 }
68}
69
70fn current_working_directory() -> Option<PathBuf> {
71 std::env::current_dir().ok()
72}