diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-05-23 00:32:46 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-05-23 00:32:46 +0300 |
| commit | 3de6ea799965a7d2aad0f7db2f23f54cd24cb039 (patch) | |
| tree | c9233a7f3d432aed7761c9db9c0072fee4ff5de2 /src/config | |
| parent | 0fec1199671becba511e03d98a4921e375a46fe3 (diff) | |
feat: configure new terminal cwd
Diffstat (limited to 'src/config')
| -rw-r--r-- | src/config/model.rs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/config/model.rs b/src/config/model.rs index 215e6f32..68a55b0f 100644 --- a/src/config/model.rs +++ b/src/config/model.rs @@ -39,11 +39,37 @@ pub struct ToastConfig { pub delivery: ToastDelivery, } +#[derive(Debug, Clone, Default, PartialEq, Eq)] +pub enum NewTerminalCwdConfig { + #[default] + Follow, + Home, + Current, + Path(String), +} + +impl<'de> Deserialize<'de> for NewTerminalCwdConfig { + fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> + where + D: Deserializer<'de>, + { + let value = String::deserialize(deserializer)?; + match value.trim() { + "" | "follow" => Ok(Self::Follow), + "home" => Ok(Self::Home), + "current" => Ok(Self::Current), + _ => Ok(Self::Path(value)), + } + } +} + #[derive(Debug, Default, Deserialize)] #[serde(default)] pub struct TerminalConfig { /// Executable used for new interactive panes. Empty means SHELL, then /bin/sh. pub default_shell: String, + /// CWD policy for new interactive panes, tabs, and workspaces. + pub new_cwd: NewTerminalCwdConfig, } #[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] @@ -434,6 +460,36 @@ default_shell = "nu" } #[test] + fn terminal_new_cwd_defaults_follow_and_parses() { + let default_config = Config::default(); + assert_eq!( + default_config.terminal.new_cwd, + NewTerminalCwdConfig::Follow + ); + + let config: Config = toml::from_str( + r#" +[terminal] +new_cwd = "home" +"#, + ) + .unwrap(); + assert_eq!(config.terminal.new_cwd, NewTerminalCwdConfig::Home); + + let config: Config = toml::from_str( + r#" +[terminal] +new_cwd = "~/Projects" +"#, + ) + .unwrap(); + assert_eq!( + config.terminal.new_cwd, + NewTerminalCwdConfig::Path("~/Projects".into()) + ); + } + + #[test] fn agent_panel_scope_config_parses() { let toml = r#" [ui] |
