diff options
author | Kangaxx-0 <85712372+Kangaxx-0@users.noreply.github.com> | 2023-04-18 07:35:51 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-18 16:35:51 +0200 |
commit | 4c87b1e6bd59107355f12a7eac00ccd54d7714b6 (patch) | |
tree | 4ab8589f920119c8915806a78e38d81d35791757 /zellij-utils | |
parent | cecd7b2b7f54a31425ec708a457fdfad363d3cfd (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-utils')
14 files changed, 31 insertions, 0 deletions
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" @@ -340,6 +341,11 @@ mod config_test { "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")), "Option set in config" 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<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, 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, |