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, 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, 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, Option, Option, Vec, @@ -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, ClientId), GoToTab(TabIndex, ClientId), NewTab( + Option, Option, Option, Vec, @@ -336,6 +337,7 @@ pub(crate) fn pty_thread_main(mut pty: Pty, layout: Box) -> 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) -> 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, layout: TiledPaneLayout, floating_panes_layout: Vec, default_shell: Option, @@ -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, ClientId), UndoRenamePane(ClientId), NewTab( + Option, Option, Option, Vec, @@ -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 @@ -4,6 +4,7 @@ expression: "format!(\"{:#?}\", new_tab_action)" --- Some( NewTab( + None, None, Some( TiledPaneLayout { 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 @@ -4,6 +4,7 @@ assertion_line: 2448 expression: "format!(\"{:#?}\", new_tab_instruction)" --- NewTab( + None, None, Some( TiledPaneLayout { 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 @@ -27,6 +27,7 @@ expression: "format!(\"{:#?}\", * received_plugin_instructions.lock().unwrap())" ], ), NewTab( + None, None, Some( TiledPaneLayout { @@ -187,6 +188,7 @@ expression: "format!(\"{:#?}\", * received_plugin_instructions.lock().unwrap())" ], ), NewTab( + None, None, Some( TiledPaneLayout { 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 @@ -27,6 +27,7 @@ expression: "format!(\"{:#?}\", * received_plugin_instructions.lock().unwrap())" ], ), NewTab( + None, None, Some( TiledPaneLayout { @@ -187,6 +188,7 @@ expression: "format!(\"{:#?}\", * received_plugin_instructions.lock().unwrap())" ], ), NewTab( + None, None, Some( TiledPaneLayout { diff --git a/zellij-utils/assets/config/default.kdl b/zellij-utils/assets/config/default.kdl index 1e8ddd7c3..57106681d 100644 --- a/zellij-utils/assets/config/default.kdl +++ b/zellij-utils/assets/config/default.kdl @@ -200,6 +200,10 @@ plugins { // // default_shell "fish" +// Choose the path to override cwd that zellij will use for opening new panes +// +// default_cwd "" + // Toggle between having pane frames around the panes // Options: // - true (default) diff --git a/zellij-utils/src/input/config.rs b/zellij-utils/src/input/config.rs index 9d0c6da39..8022ea28e 100644 --- a/zellij-utils/src/input/config.rs +++ b/zellij-utils/src/input/config.rs @@ -303,6 +303,7 @@ mod config_test { theme "my cool theme" default_mode "locked" default_shell "/path/to/my/shell" + default_cwd "/path" default_layout "/path/to/my/layout.kdl" layout_dir "/path/to/my/layout-dir" theme_dir "/path/to/my/theme-dir" @@ -339,6 +340,11 @@ mod config_test { Some(PathBuf::from("/path/to/my/shell")), "Option set in config" ); + assert_eq!( + config.options.default_cwd, + Some(PathBuf::from("/path")), + "Option set in config" + ); assert_eq!( config.options.default_layout, Some(PathBuf::from("/path/to/my/layout.kdl")), diff --git a/zellij-utils/src/input/options.rs b/zellij-utils/src/input/options.rs index 8f7902364..68ef49e0f 100644 --- a/zellij-utils/src/input/options.rs +++ b/zellij-utils/src/input/options.rs @@ -52,6 +52,9 @@ pub struct Options { /// Set the default shell #[clap(long, value_parser)] pub default_shell: Option, + /// Set the default cwd + #[clap(long, value_parser)] + pub default_cwd: Option, /// Set the default layout #[clap(long, value_parser)] pub default_layout: Option, @@ -167,6 +170,7 @@ impl Options { let simplified_ui = other.simplified_ui.or(self.simplified_ui); let default_mode = other.default_mode.or(self.default_mode); let default_shell = other.default_shell.or_else(|| self.default_shell.clone()); + let default_cwd = other.default_cwd.or_else(|| self.default_cwd.clone()); let default_layout = other.default_layout.or_else(|| self.default_layout.clone()); let layout_dir = other.layout_dir.or_else(|| self.layout_dir.clone()); let theme_dir = other.theme_dir.or_else(|| self.theme_dir.clone()); @@ -189,6 +193,7 @@ impl Options { theme, default_mode, default_shell, + default_cwd, default_layout, layout_dir, theme_dir, @@ -230,6 +235,7 @@ impl Options { let default_mode = other.default_mode.or(self.default_mode); let default_shell = other.default_shell.or_else(|| self.default_shell.clone()); + let default_cwd = other.default_cwd.or_else(|| self.default_cwd.clone()); let default_layout = other.default_layout.or_else(|| self.default_layout.clone()); let layout_dir = other.layout_dir.or_else(|| self.layout_dir.clone()); let theme_dir = other.theme_dir.or_else(|| self.theme_dir.clone()); @@ -252,6 +258,7 @@ impl Options { theme, default_mode, default_shell, + default_cwd, default_layout, layout_dir, theme_dir, @@ -310,6 +317,7 @@ impl From for Options { theme: opts.theme, default_mode: opts.default_mode, default_shell: opts.default_shell, + default_cwd: opts.default_cwd, default_layout: opts.default_layout, layout_dir: opts.layout_dir, theme_dir: opts.theme_dir, diff --git a/zellij-utils/src/kdl/mod.rs b/zellij-utils/src/kdl/mod.rs index fa11077c0..a892cf8c3 100644 --- a/zellij-utils/src/kdl/mod.rs +++ b/zellij-utils/src/kdl/mod.rs @@ -1304,6 +1304,8 @@ impl Options { let default_shell = kdl_property_first_arg_as_string_or_error!(kdl_options, "default_shell") .map(|(string, _entry)| PathBuf::from(string)); + let default_cwd = kdl_property_first_arg_as_string_or_error!(kdl_options, "default_cwd") + .map(|(string, _entry)| PathBuf::from(string)); let pane_frames = kdl_property_first_arg_as_bool_or_error!(kdl_options, "pane_frames").map(|(v, _)| v); let auto_layout = @@ -1358,6 +1360,7 @@ impl Options { theme, default_mode, default_shell, + default_cwd, default_layout, layout_dir, theme_dir, diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__cli_arguments_override_config_options.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__cli_arguments_override_config_options.snap index dfe128dab..0ef13c025 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__cli_arguments_override_config_options.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__cli_arguments_override_config_options.snap @@ -10,6 +10,7 @@ Options { theme: None, default_mode: None, default_shell: None, + default_cwd: None, default_layout: None, layout_dir: None, theme_dir: None, diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__cli_arguments_override_layout_options.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__cli_arguments_override_layout_options.snap index 881d22ee3..ac3f4bf1e 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__cli_arguments_override_layout_options.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__cli_arguments_override_layout_options.snap @@ -8,6 +8,7 @@ Options { theme: None, default_mode: None, default_shell: None, + default_cwd: None, default_layout: None, layout_dir: None, theme_dir: None, diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments-3.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments-3.snap index b8c2a501b..cf623d2e5 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments-3.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments-3.snap @@ -8,6 +8,7 @@ Options { theme: None, default_mode: None, default_shell: None, + default_cwd: None, default_layout: None, layout_dir: None, theme_dir: None, diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments.snap index a51321f89..c9267c329 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments.snap @@ -3525,6 +3525,7 @@ Config { theme: None, default_mode: None, default_shell: None, + default_cwd: None, default_layout: None, layout_dir: None, theme_dir: None, diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_env_vars_override_config_env_vars.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_env_vars_override_config_env_vars.snap index 226385df8..2c8b20956 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_env_vars_override_config_env_vars.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_env_vars_override_config_env_vars.snap @@ -3525,6 +3525,7 @@ Config { theme: None, default_mode: None, default_shell: None, + default_cwd: None, default_layout: None, layout_dir: None, theme_dir: None, diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_keybinds_override_config_keybinds.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_keybinds_override_config_keybinds.snap index 55574997d..4cea16134 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_keybinds_override_config_keybinds.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_keybinds_override_config_keybinds.snap @@ -65,6 +65,7 @@ Config { theme: None, default_mode: None, default_shell: None, + default_cwd: None, default_layout: None, layout_dir: None, theme_dir: None, diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_options_override_config_options.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_options_override_config_options.snap index 2a3e7acea..d354e6fed 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_options_override_config_options.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_options_override_config_options.snap @@ -8,6 +8,7 @@ Options { theme: None, default_mode: None, default_shell: None, + default_cwd: None, default_layout: None, layout_dir: None, theme_dir: None, diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_plugins_override_config_plugins.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_plugins_override_config_plugins.snap index 772eb5266..5f55ff1d7 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_plugins_override_config_plugins.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_plugins_override_config_plugins.snap @@ -3525,6 +3525,7 @@ Config { theme: None, default_mode: None, default_shell: None, + default_cwd: None, default_layout: None, layout_dir: None, theme_dir: None, diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_themes_override_config_themes.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_themes_override_config_themes.snap index e4532bbe3..4534d4912 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_themes_override_config_themes.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_themes_override_config_themes.snap @@ -3525,6 +3525,7 @@ Config { theme: None, default_mode: None, default_shell: None, + default_cwd: None, default_layout: None, layout_dir: None, theme_dir: None, diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_ui_config_overrides_config_ui_config.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_ui_config_overrides_config_ui_config.snap index 001041fce..414b1d84b 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_ui_config_overrides_config_ui_config.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_ui_config_overrides_config_ui_config.snap @@ -3525,6 +3525,7 @@ Config { theme: None, default_mode: None, default_shell: None, + default_cwd: None, default_layout: None, layout_dir: None, theme_dir: None,