From 618e0f7a34e51ad9f500320ffca320b56c667090 Mon Sep 17 00:00:00 2001 From: Aram Drevekenin Date: Mon, 14 Oct 2024 16:44:28 +0200 Subject: [PATCH] fix(plugins): allow switching to a new session with cwd without specifying a layout (#3676) --- src/commands.rs | 4 ++++ zellij-server/src/plugins/mod.rs | 10 +++++++--- zellij-tile/src/shim.rs | 12 ++++++++++++ zellij-utils/src/data.rs | 2 +- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index 605abdf8..dba2c9d7 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -483,6 +483,10 @@ pub(crate) fn start_client(opts: CliArgs) { log::error!("Failed to parse new session layout: {:?}", e); }, } + } else { + if let Some(cwd) = reconnect_to_session.cwd.as_ref() { + config_options.default_cwd = Some(cwd.clone()); + } } is_a_reconnect = true; diff --git a/zellij-server/src/plugins/mod.rs b/zellij-server/src/plugins/mod.rs index 564af769..3a8caec6 100644 --- a/zellij-server/src/plugins/mod.rs +++ b/zellij-server/src/plugins/mod.rs @@ -426,9 +426,13 @@ pub(crate) fn plugin_thread_main( let mut plugin_ids: HashMap> = HashMap::new(); tab_layout = tab_layout.or_else(|| Some(layout.new_tab().0)); - tab_layout - .as_mut() - .map(|t| t.populate_plugin_aliases_in_layout(&plugin_aliases)); + tab_layout.as_mut().map(|t| { + t.populate_plugin_aliases_in_layout(&plugin_aliases); + if let Some(cwd) = cwd.as_ref() { + t.add_cwd_to_layout(cwd); + } + t + }); floating_panes_layout.iter_mut().for_each(|f| { f.run .as_mut() diff --git a/zellij-tile/src/shim.rs b/zellij-tile/src/shim.rs index 8ede34c4..7e81d505 100644 --- a/zellij-tile/src/shim.rs +++ b/zellij-tile/src/shim.rs @@ -721,6 +721,18 @@ pub fn switch_session_with_layout(name: Option<&str>, layout: LayoutInfo, cwd: O unsafe { host_run_plugin_command() }; } +/// Switch to a session with the given name, create one if no name is given +pub fn switch_session_with_cwd(name: Option<&str>, cwd: Option) { + let plugin_command = PluginCommand::SwitchSession(ConnectToSession { + name: name.map(|n| n.to_string()), + cwd, + ..Default::default() + }); + let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap(); + object_to_stdout(&protobuf_plugin_command.encode_to_vec()); + unsafe { host_run_plugin_command() }; +} + /// Switch to a session with the given name, focusing either the provided pane_id or the provided /// tab position (in that order) pub fn switch_session_with_focus( diff --git a/zellij-utils/src/data.rs b/zellij-utils/src/data.rs index 8c2d2081..64cded6b 100644 --- a/zellij-utils/src/data.rs +++ b/zellij-utils/src/data.rs @@ -960,7 +960,7 @@ impl PermissionType { "Access Zellij state (Panes, Tabs and UI)".to_owned() }, PermissionType::ChangeApplicationState => { - "Change Zellij state (Panes, Tabs and UI)".to_owned() + "Change Zellij state (Panes, Tabs and UI) and run commands".to_owned() }, PermissionType::OpenFiles => "Open files (eg. for editing)".to_owned(), PermissionType::RunCommands => "Run commands".to_owned(),