diff options
author | Aram Drevekenin <aram@poor.dev> | 2024-04-05 17:12:31 +0200 |
---|---|---|
committer | Aram Drevekenin <aram@poor.dev> | 2024-04-05 17:12:31 +0200 |
commit | 564409a65811047a38d4c5399bc48ec63c339e8b (patch) | |
tree | 358a7413375132bc5b568288d3b3b4ad5bc9ca57 | |
parent | 014a3a7e74ad9a8b99e4ab99440060385ddd174e (diff) |
fix(plugins): populate caller_cwd for all aliases
-rw-r--r-- | zellij-server/src/pty.rs | 12 | ||||
-rw-r--r-- | zellij-server/src/screen.rs | 2 | ||||
-rw-r--r-- | zellij-utils/src/input/actions.rs | 12 | ||||
-rw-r--r-- | zellij-utils/src/input/layout.rs | 14 |
4 files changed, 29 insertions, 11 deletions
diff --git a/zellij-server/src/pty.rs b/zellij-server/src/pty.rs index c4e810536..5877e56df 100644 --- a/zellij-server/src/pty.rs +++ b/zellij-server/src/pty.rs @@ -1348,7 +1348,7 @@ impl Pty { should_float: Option<bool>, should_open_in_place: bool, // should be opened in place pane_title: Option<String>, // pane title - run: RunPluginOrAlias, + mut run: RunPluginOrAlias, tab_index: usize, // tab index pane_id_to_replace: Option<PaneId>, // pane id to replace if this is to be opened "in-place" client_id: ClientId, @@ -1359,7 +1359,7 @@ impl Pty { // of the pipeline between threads and end up needing to forward this _floating_pane_coordinates: Option<FloatingPaneCoordinates>, ) -> Result<()> { - let cwd = cwd.or_else(|| { + let get_focused_cwd = || { self.active_panes .get(&client_id) .and_then(|pane| match pane { @@ -1372,8 +1372,14 @@ impl Pty { .as_ref() .and_then(|input| input.get_cwd(Pid::from_raw(id))) }) - }); + }; + let cwd = cwd.or_else(get_focused_cwd); + + if let RunPluginOrAlias::Alias(alias) = &mut run { + let cwd = get_focused_cwd(); + alias.set_caller_cwd_if_not_set(cwd); + } self.bus.senders.send_to_plugin(PluginInstruction::Load( should_float, should_open_in_place, diff --git a/zellij-server/src/screen.rs b/zellij-server/src/screen.rs index 5384987de..f5458c1a8 100644 --- a/zellij-server/src/screen.rs +++ b/zellij-server/src/screen.rs @@ -3544,7 +3544,7 @@ pub(crate) fn screen_thread_main( should_float, Some(run_plugin), None, - None, + Some(client_id), ) }, ?); } else if let Some(active_tab) = diff --git a/zellij-utils/src/input/actions.rs b/zellij-utils/src/input/actions.rs index 61a789d1f..52c18fb50 100644 --- a/zellij-utils/src/input/actions.rs +++ b/zellij-utils/src/input/actions.rs @@ -380,15 +380,13 @@ impl Action { }) }, Err(_) => { - let mut user_configuration = - configuration.map(|c| c.inner().clone()).unwrap_or_default(); - user_configuration - .insert("caller_cwd".to_owned(), current_dir.display().to_string()); - RunPluginOrAlias::Alias(PluginAlias::new( + let mut plugin_alias = PluginAlias::new( &plugin, - &Some(user_configuration), + &configuration.map(|c| c.inner().clone()), alias_cwd, - )) + ); + plugin_alias.set_caller_cwd_if_not_set(Some(current_dir)); + RunPluginOrAlias::Alias(plugin_alias) }, }; if floating { diff --git a/zellij-utils/src/input/layout.rs b/zellij-utils/src/input/layout.rs index cede261e7..a8a323594 100644 --- a/zellij-utils/src/input/layout.rs +++ b/zellij-utils/src/input/layout.rs @@ -456,6 +456,20 @@ impl PluginAlias { ..Default::default() } } + pub fn set_caller_cwd_if_not_set(&mut self, caller_cwd: Option<PathBuf>) { + // we do this only for an alias because in all other cases this will be handled by the + // "cwd" configuration key above + // for an alias we might have cases where the cwd is defined on the alias but we still + // want to pass the "caller" cwd for the plugin the alias resolves into (eg. a + // filepicker that has access to the whole filesystem but wants to start in a specific + // folder) + if let Some(caller_cwd) = caller_cwd { + if self.configuration.as_ref().map(|c| c.inner().get("caller_cwd").is_none()).unwrap_or(true) { + let configuration = self.configuration.get_or_insert_with(|| PluginUserConfiguration::new(BTreeMap::new())); + configuration.insert("caller_cwd", caller_cwd.display().to_string()); + } + } + } } #[allow(clippy::derive_hash_xor_eq)] |