mirror of
https://github.com/zellij-org/zellij.git
synced 2024-11-26 10:55:12 +03:00
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`
This commit is contained in:
parent
cecd7b2b7f
commit
4c87b1e6bd
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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 =
|
||||
|
@ -464,6 +464,7 @@ pub(crate) fn route_action(
|
||||
session
|
||||
.senders
|
||||
.send_to_screen(ScreenInstruction::NewTab(
|
||||
None,
|
||||
shell,
|
||||
tab_layout,
|
||||
floating_panes_layout,
|
||||
|
@ -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![],
|
||||
|
@ -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
|
||||
|
@ -4,6 +4,7 @@ expression: "format!(\"{:#?}\", new_tab_action)"
|
||||
---
|
||||
Some(
|
||||
NewTab(
|
||||
None,
|
||||
None,
|
||||
Some(
|
||||
TiledPaneLayout {
|
||||
|
@ -4,6 +4,7 @@ assertion_line: 2448
|
||||
expression: "format!(\"{:#?}\", new_tab_instruction)"
|
||||
---
|
||||
NewTab(
|
||||
None,
|
||||
None,
|
||||
Some(
|
||||
TiledPaneLayout {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
@ -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")),
|
||||
|
@ -52,6 +52,9 @@ pub struct Options {
|
||||
/// Set the default shell
|
||||
#[clap(long, value_parser)]
|
||||
pub default_shell: Option<PathBuf>,
|
||||
/// Set the default cwd
|
||||
#[clap(long, value_parser)]
|
||||
pub default_cwd: Option<PathBuf>,
|
||||
/// Set the default layout
|
||||
#[clap(long, value_parser)]
|
||||
pub default_layout: Option<PathBuf>,
|
||||
@ -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<CliOptions> 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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user