summaryrefslogtreecommitdiffstats
path: root/zellij-server
diff options
context:
space:
mode:
authorKangaxx-0 <85712372+Kangaxx-0@users.noreply.github.com>2023-04-18 07:35:51 -0700
committerGitHub <noreply@github.com>2023-04-18 16:35:51 +0200
commit4c87b1e6bd59107355f12a7eac00ccd54d7714b6 (patch)
tree4ab8589f920119c8915806a78e38d81d35791757 /zellij-server
parentcecd7b2b7f54a31425ec708a457fdfad363d3cfd (diff)
feat: support default cwd (#2290)
* init commit * add default config to kdl file * change the field from `default_cwd` to `override_cwd` * change back to default_cwd * fix test * default cwd works without `default_shell`
Diffstat (limited to 'zellij-server')
-rw-r--r--zellij-server/src/lib.rs3
-rw-r--r--zellij-server/src/plugins/mod.rs3
-rw-r--r--zellij-server/src/pty.rs6
-rw-r--r--zellij-server/src/route.rs1
-rw-r--r--zellij-server/src/screen.rs5
-rw-r--r--zellij-server/src/unit/screen_tests.rs2
-rw-r--r--zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_new_tab_action_default_params.snap1
-rw-r--r--zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_new_tab_action_with_name_and_layout.snap1
-rw-r--r--zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_rename_tab.snap2
-rw-r--r--zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_undo_rename_tab.snap2
10 files changed, 25 insertions, 1 deletions
diff --git a/zellij-server/src/lib.rs b/zellij-server/src/lib.rs
index 45ea85940..bf0f1a82f 100644
--- a/zellij-server/src/lib.rs
+++ b/zellij-server/src/lib.rs
@@ -343,9 +343,11 @@ pub fn start_server(mut os_input: Box<dyn ServerOsApi>, socket_path: PathBuf) {
let default_shell = config_options.default_shell.map(|shell| {
TerminalAction::RunCommand(RunCommand {
command: shell,
+ cwd: config_options.default_cwd.clone(),
..Default::default()
})
});
+ let cwd = config_options.default_cwd;
let spawn_tabs = |tab_layout, floating_panes_layout, tab_name, swap_layouts| {
session_data
@@ -355,6 +357,7 @@ pub fn start_server(mut os_input: Box<dyn ServerOsApi>, socket_path: PathBuf) {
.unwrap()
.senders
.send_to_screen(ScreenInstruction::NewTab(
+ cwd.clone(),
default_shell.clone(),
tab_layout,
floating_panes_layout,
diff --git a/zellij-server/src/plugins/mod.rs b/zellij-server/src/plugins/mod.rs
index e1884b1e6..2aca679a3 100644
--- a/zellij-server/src/plugins/mod.rs
+++ b/zellij-server/src/plugins/mod.rs
@@ -36,6 +36,7 @@ pub enum PluginInstruction {
AddClient(ClientId),
RemoveClient(ClientId),
NewTab(
+ Option<PathBuf>,
Option<TerminalAction>,
Option<TiledPaneLayout>,
Vec<FloatingPaneLayout>,
@@ -112,6 +113,7 @@ pub(crate) fn plugin_thread_main(
wasm_bridge.remove_client(client_id);
},
PluginInstruction::NewTab(
+ cwd,
terminal_action,
tab_layout,
floating_panes_layout,
@@ -142,6 +144,7 @@ pub(crate) fn plugin_thread_main(
}
}
drop(bus.senders.send_to_pty(PtyInstruction::NewTab(
+ cwd,
terminal_action,
tab_layout,
floating_panes_layout,
diff --git a/zellij-server/src/pty.rs b/zellij-server/src/pty.rs
index d28b333b7..ea2d4fe44 100644
--- a/zellij-server/src/pty.rs
+++ b/zellij-server/src/pty.rs
@@ -48,6 +48,7 @@ pub enum PtyInstruction {
UpdateActivePane(Option<PaneId>, ClientId),
GoToTab(TabIndex, ClientId),
NewTab(
+ Option<PathBuf>,
Option<TerminalAction>,
Option<TiledPaneLayout>,
Vec<FloatingPaneLayout>,
@@ -336,6 +337,7 @@ pub(crate) fn pty_thread_main(mut pty: Pty, layout: Box<Layout>) -> Result<()> {
})?;
},
PtyInstruction::NewTab(
+ cwd,
terminal_action,
tab_layout,
floating_panes_layout,
@@ -351,6 +353,7 @@ pub(crate) fn pty_thread_main(mut pty: Pty, layout: Box<Layout>) -> Result<()> {
floating_panes_layout
};
pty.spawn_terminals_for_layout(
+ cwd,
tab_layout.unwrap_or_else(|| layout.new_tab().0),
floating_panes_layout,
terminal_action.clone(),
@@ -591,6 +594,7 @@ impl Pty {
}
pub fn spawn_terminals_for_layout(
&mut self,
+ cwd: Option<PathBuf>,
layout: TiledPaneLayout,
floating_panes_layout: Vec<FloatingPaneLayout>,
default_shell: Option<TerminalAction>,
@@ -601,7 +605,7 @@ impl Pty {
let err_context = || format!("failed to spawn terminals for layout for client {client_id}");
let mut default_shell =
- default_shell.unwrap_or_else(|| self.get_default_terminal(None, None));
+ default_shell.unwrap_or_else(|| self.get_default_terminal(cwd, None));
self.fill_cwd(&mut default_shell, client_id);
let extracted_run_instructions = layout.extract_run_instructions();
let extracted_floating_run_instructions =
diff --git a/zellij-server/src/route.rs b/zellij-server/src/route.rs
index c240ec40d..c14d0c14e 100644
--- a/zellij-server/src/route.rs
+++ b/zellij-server/src/route.rs
@@ -464,6 +464,7 @@ pub(crate) fn route_action(
session
.senders
.send_to_screen(ScreenInstruction::NewTab(
+ None,
shell,
tab_layout,
floating_panes_layout,
diff --git a/zellij-server/src/screen.rs b/zellij-server/src/screen.rs
index ecd1c7521..8b5cc5d64 100644
--- a/zellij-server/src/screen.rs
+++ b/zellij-server/src/screen.rs
@@ -2,6 +2,7 @@
use std::cell::RefCell;
use std::collections::{BTreeMap, HashMap, HashSet};
+use std::path::PathBuf;
use std::rc::Rc;
use std::str;
@@ -190,6 +191,7 @@ pub enum ScreenInstruction {
UpdatePaneName(Vec<u8>, ClientId),
UndoRenamePane(ClientId),
NewTab(
+ Option<PathBuf>,
Option<TerminalAction>,
Option<TiledPaneLayout>,
Vec<FloatingPaneLayout>,
@@ -2097,6 +2099,7 @@ pub(crate) fn screen_thread_main(
screen.render()?;
},
ScreenInstruction::NewTab(
+ cwd,
default_shell,
layout,
floating_panes_layout,
@@ -2111,6 +2114,7 @@ pub(crate) fn screen_thread_main(
.bus
.senders
.send_to_plugin(PluginInstruction::NewTab(
+ cwd,
default_shell,
layout,
floating_panes_layout,
@@ -2202,6 +2206,7 @@ pub(crate) fn screen_thread_main(
.bus
.senders
.send_to_plugin(PluginInstruction::NewTab(
+ None,
default_shell,
None,
vec![],
diff --git a/zellij-server/src/unit/screen_tests.rs b/zellij-server/src/unit/screen_tests.rs
index adc7b0441..d4cd8c1e7 100644
--- a/zellij-server/src/unit/screen_tests.rs
+++ b/zellij-server/src/unit/screen_tests.rs
@@ -299,6 +299,7 @@ impl MockScreen {
let tab_name = None;
let tab_index = self.last_opened_tab_index.map(|l| l + 1).unwrap_or(0);
let _ = self.to_screen.send(ScreenInstruction::NewTab(
+ None,
default_shell,
Some(pane_layout.clone()),
vec![], // floating_panes_layout
@@ -329,6 +330,7 @@ impl MockScreen {
pane_ids.push((i as u32, None));
}
let _ = self.to_screen.send(ScreenInstruction::NewTab(
+ None,
default_shell,
Some(tab_layout.clone()),
vec![], // floating_panes_layout
diff --git a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_new_tab_action_default_params.snap b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_new_tab_action_default_params.snap
index 42eeaa7c4..a25b01b47 100644
--- a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_new_tab_action_default_params.snap
+++ b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_new_tab_action_default_params.snap
@@ -5,6 +5,7 @@ expression: "format!(\"{:#?}\", new_tab_action)"
Some(
NewTab(
None,
+ None,
Some(
TiledPaneLayout {
children_split_direction: Vertical,
diff --git a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_new_tab_action_with_name_and_layout.snap b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_new_tab_action_with_name_and_layout.snap
index f06ae128c..cd5300d08 100644
--- a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_new_tab_action_with_name_and_layout.snap
+++ b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_new_tab_action_with_name_and_layout.snap
@@ -5,6 +5,7 @@ expression: "format!(\"{:#?}\", new_tab_instruction)"
---
NewTab(
None,
+ None,
Some(
TiledPaneLayout {
children_split_direction: Horizontal,
diff --git a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_rename_tab.snap b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_rename_tab.snap
index 596b5e800..f5e86b280 100644
--- a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_rename_tab.snap
+++ b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_rename_tab.snap
@@ -28,6 +28,7 @@ expression: "format!(\"{:#?}\", * received_plugin_instructions.lock().unwrap())"
),
NewTab(
None,
+ None,
Some(
TiledPaneLayout {
children_split_direction: Horizontal,
@@ -188,6 +189,7 @@ expression: "format!(\"{:#?}\", * received_plugin_instructions.lock().unwrap())"
),
NewTab(
None,
+ None,
Some(
TiledPaneLayout {
children_split_direction: Vertical,
diff --git a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_undo_rename_tab.snap b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_undo_rename_tab.snap
index 1a80ff086..bae48188f 100644
--- a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_undo_rename_tab.snap
+++ b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_undo_rename_tab.snap
@@ -28,6 +28,7 @@ expression: "format!(\"{:#?}\", * received_plugin_instructions.lock().unwrap())"
),
NewTab(
None,
+ None,
Some(
TiledPaneLayout {
children_split_direction: Horizontal,
@@ -188,6 +189,7 @@ expression: "format!(\"{:#?}\", * received_plugin_instructions.lock().unwrap())"
),
NewTab(
None,
+ None,
Some(
TiledPaneLayout {
children_split_direction: Vertical,