From 06bcd06a17be3bd242e2b8230dd9b803b1969f3c Mon Sep 17 00:00:00 2001 From: Ogulcan Celik Date: Thu, 21 May 2026 15:17:37 +0300 Subject: feat: use local keybindings for remote attach --- src/config.rs | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'src/config.rs') diff --git a/src/config.rs b/src/config.rs index 48ebb8f6..b6406874 100644 --- a/src/config.rs +++ b/src/config.rs @@ -19,7 +19,7 @@ pub use self::{ }, model::{ validated_sidebar_bounds, AgentPanelScopeConfig, Config, ConfigReloadReport, - ConfigReloadStatus, ToastConfig, ToastDelivery, + ConfigReloadStatus, KeysConfig, ToastConfig, ToastDelivery, }, sound::SoundConfig, theme::{parse_color, CustomThemeColors, ThemeConfig}, @@ -67,4 +67,46 @@ impl Config { Err(diagnostics) } } + + pub(crate) fn local_keybindings_profile_toml(&self) -> Result { + let mut keys = self.keys.clone(); + keys.command.clear(); + + #[derive(serde::Serialize)] + struct KeysProfile { + keys: KeysConfig, + } + + toml::to_string_pretty(&KeysProfile { keys }) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn local_keybindings_profile_includes_defaults_and_excludes_commands() { + let config: Config = toml::from_str( + r#" +[keys] +prefix = "ctrl+a" +new_tab = "prefix+t" + +[[keys.command]] +key = "prefix+g" +command = "lazygit" +"#, + ) + .unwrap(); + + let profile = config.local_keybindings_profile_toml().unwrap(); + assert!(profile.contains("[keys]")); + assert!(profile.contains("prefix = \"ctrl+a\"")); + assert!(profile.contains("new_tab = \"prefix+t\"")); + assert!(profile.contains("next_tab = \"prefix+n\"")); + assert!(!profile.contains("lazygit")); + assert!(!profile.contains("command =")); + assert!(!profile.contains("[[keys.command]]")); + } } -- cgit v1.2.3