diff options
author | Aram Drevekenin <aram@poor.dev> | 2024-02-29 16:26:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-29 16:26:25 +0100 |
commit | 896b09aa6f9190b4dc838314b028b63e0f2461b7 (patch) | |
tree | 80aeda55e00e51dfc3d0fd8b6b4f6e6bbf493efd /zellij-utils/src | |
parent | d5bedd0e83dfa531e922f89f9792d20384eb2dc3 (diff) |
feat(plugins): allow specifying the cwd when switching sessions (#3172)
* feat(plugins): allow specifying the cwd when switching sessions
* style(fmt): rustfmt
Diffstat (limited to 'zellij-utils/src')
-rw-r--r-- | zellij-utils/src/data.rs | 1 | ||||
-rw-r--r-- | zellij-utils/src/input/layout.rs | 28 | ||||
-rw-r--r-- | zellij-utils/src/plugin_api/plugin_command.proto | 1 | ||||
-rw-r--r-- | zellij-utils/src/plugin_api/plugin_command.rs | 2 |
4 files changed, 31 insertions, 1 deletions
diff --git a/zellij-utils/src/data.rs b/zellij-utils/src/data.rs index 6e0dce94f..63ccccced 100644 --- a/zellij-utils/src/data.rs +++ b/zellij-utils/src/data.rs @@ -1095,6 +1095,7 @@ pub struct ConnectToSession { pub tab_position: Option<usize>, pub pane_id: Option<(u32, bool)>, // (id, is_plugin) pub layout: Option<LayoutInfo>, + pub cwd: Option<PathBuf>, } impl ConnectToSession { diff --git a/zellij-utils/src/input/layout.rs b/zellij-utils/src/input/layout.rs index 82da8cbf0..74242cff8 100644 --- a/zellij-utils/src/input/layout.rs +++ b/zellij-utils/src/input/layout.rs @@ -211,6 +211,16 @@ impl RunPluginOrAlias { } self } + pub fn add_initial_cwd(&mut self, initial_cwd: &PathBuf) { + match self { + RunPluginOrAlias::RunPlugin(ref mut run_plugin) => { + run_plugin.initial_cwd = Some(initial_cwd.clone()); + }, + RunPluginOrAlias::Alias(ref mut alias) => { + alias.initial_cwd = Some(initial_cwd.clone()); + }, + } + } } #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)] @@ -305,7 +315,9 @@ impl Run { Run::Cwd(path) => { *path = cwd.join(&path); }, - _ => {}, // plugins aren't yet supported + Run::Plugin(run_plugin_or_alias) => { + run_plugin_or_alias.add_initial_cwd(&cwd); + }, } } pub fn add_args(&mut self, args: Option<Vec<String>>) { @@ -1365,6 +1377,20 @@ impl Layout { } } } + pub fn add_cwd_to_layout(&mut self, cwd: &PathBuf) { + for (_, tiled_pane_layout, floating_panes) in self.tabs.iter_mut() { + tiled_pane_layout.add_cwd_to_layout(&cwd); + for floating_pane in floating_panes { + floating_pane.add_cwd_to_layout(&cwd); + } + } + if let Some((tiled_pane_layout, floating_panes)) = self.template.as_mut() { + tiled_pane_layout.add_cwd_to_layout(&cwd); + for floating_pane in floating_panes { + floating_pane.add_cwd_to_layout(&cwd); + } + } + } } fn split_space( diff --git a/zellij-utils/src/plugin_api/plugin_command.proto b/zellij-utils/src/plugin_api/plugin_command.proto index d85afeed6..eecae43b8 100644 --- a/zellij-utils/src/plugin_api/plugin_command.proto +++ b/zellij-utils/src/plugin_api/plugin_command.proto @@ -194,6 +194,7 @@ message SwitchSessionPayload { optional uint32 pane_id = 3; optional bool pane_id_is_plugin = 4; optional event.LayoutInfo layout = 5; + optional string cwd = 6; } message RequestPluginPermissionPayload { diff --git a/zellij-utils/src/plugin_api/plugin_command.rs b/zellij-utils/src/plugin_api/plugin_command.rs index 6ce7422e6..ab9d52940 100644 --- a/zellij-utils/src/plugin_api/plugin_command.rs +++ b/zellij-utils/src/plugin_api/plugin_command.rs @@ -689,6 +689,7 @@ impl TryFrom<ProtobufPluginCommand> for PluginCommand { tab_position: payload.tab_position.map(|p| p as usize), pane_id, layout: payload.layout.and_then(|l| l.try_into().ok()), + cwd: payload.cwd.map(|c| PathBuf::from(c)), })) }, _ => Err("Mismatched payload for SwitchSession"), @@ -1222,6 +1223,7 @@ impl TryFrom<PluginCommand> for ProtobufPluginCommand { pane_id: switch_to_session.pane_id.map(|p| p.0), pane_id_is_plugin: switch_to_session.pane_id.map(|p| p.1), layout: switch_to_session.layout.and_then(|l| l.try_into().ok()), + cwd: switch_to_session.cwd.map(|c| c.display().to_string()), })), }), PluginCommand::OpenTerminalInPlace(cwd) => Ok(ProtobufPluginCommand { |