aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-server/src/plugins
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2025-07-08 11:06:03 +0200
committerGitHub <noreply@github.com>2025-07-08 11:06:03 +0200
commit358caa180ce7c60b8923caa98cf339f897d14feb (patch)
treebb14df05b46d907a7af55ae98095abd8e9f4e7b4 /zellij-server/src/plugins
parentfix(plugins): use the terminal title when spawning terminals (#4272) (diff)
downloadsl0ppij-358caa180ce7c60b8923caa98cf339f897d14feb.tar.gz
sl0ppij-358caa180ce7c60b8923caa98cf339f897d14feb.tar.xz
sl0ppij-358caa180ce7c60b8923caa98cf339f897d14feb.zip
fix(tabs): allow setting cwd without a layout (#4273)
* working for cli and keybinding * working for plugin API * style(fmt): rustfmt * docs(changelog): add PR
Diffstat (limited to 'zellij-server/src/plugins')
-rw-r--r--zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__new_tab_plugin_command.snap8
-rw-r--r--zellij-server/src/plugins/zellij_exports.rs12
2 files changed, 14 insertions, 6 deletions
diff --git a/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__new_tab_plugin_command.snap b/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__new_tab_plugin_command.snap
index fb471bf5..ccff2ac2 100644
--- a/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__new_tab_plugin_command.snap
+++ b/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__new_tab_plugin_command.snap
@@ -4,11 +4,15 @@ expression: "format!(\"{:#?}\", new_tab_event)"
---
Some(
NewTab(
- None,
+ Some(
+ "/path/to/my/cwd",
+ ),
None,
None,
[],
- None,
+ Some(
+ "new_tab_name",
+ ),
(
[],
[],
diff --git a/zellij-server/src/plugins/zellij_exports.rs b/zellij-server/src/plugins/zellij_exports.rs
index 287e86e2..3b61f445 100644
--- a/zellij-server/src/plugins/zellij_exports.rs
+++ b/zellij-server/src/plugins/zellij_exports.rs
@@ -179,7 +179,7 @@ fn host_run_plugin_command(mut caller: Caller<'_, PluginEnv>) {
PluginCommand::NewTabsWithLayoutInfo(layout_info) => {
new_tabs_with_layout_info(env, layout_info)?
},
- PluginCommand::NewTab => new_tab(env),
+ PluginCommand::NewTab { name, cwd } => new_tab(env, name, cwd),
PluginCommand::GoToNextTab => go_to_next_tab(env),
PluginCommand::GoToPreviousTab => go_to_previous_tab(env),
PluginCommand::Resize(resize_payload) => resize(env, resize_payload),
@@ -1451,6 +1451,7 @@ fn new_tabs_with_layout_info(env: &PluginEnv, layout_info: LayoutInfo) -> Result
fn apply_layout(env: &PluginEnv, layout: Layout) {
let mut tabs_to_open = vec![];
let tabs = layout.tabs();
+ let cwd = None; // TODO: add this to the plugin API
if tabs.is_empty() {
let swap_tiled_layouts = Some(layout.swap_tiled_layouts.clone());
let swap_floating_layouts = Some(layout.swap_floating_layouts.clone());
@@ -1461,6 +1462,7 @@ fn apply_layout(env: &PluginEnv, layout: Layout) {
swap_floating_layouts,
None,
true,
+ cwd,
);
tabs_to_open.push(action);
} else {
@@ -1478,6 +1480,7 @@ fn apply_layout(env: &PluginEnv, layout: Layout) {
swap_floating_layouts,
tab_name,
should_focus_tab,
+ cwd.clone(),
);
tabs_to_open.push(action);
}
@@ -1488,8 +1491,9 @@ fn apply_layout(env: &PluginEnv, layout: Layout) {
}
}
-fn new_tab(env: &PluginEnv) {
- let action = Action::NewTab(None, vec![], None, None, None, true);
+fn new_tab(env: &PluginEnv, name: Option<String>, cwd: Option<String>) {
+ let cwd = cwd.map(|c| PathBuf::from(c));
+ let action = Action::NewTab(None, vec![], None, None, name, true, cwd);
let error_msg = || format!("Failed to open new tab");
apply_action!(action, error_msg, env);
}
@@ -2575,7 +2579,7 @@ fn check_command_permission(
| PluginCommand::SwitchToMode(..)
| PluginCommand::NewTabsWithLayout(..)
| PluginCommand::NewTabsWithLayoutInfo(..)
- | PluginCommand::NewTab
+ | PluginCommand::NewTab { .. }
| PluginCommand::GoToNextTab
| PluginCommand::GoToPreviousTab
| PluginCommand::Resize(..)