fix(config): fix shell integration keybindings not overwriting defaults (#431)

Fixes #430
This commit is contained in:
Alexandre Pasmantier 2025-03-21 21:33:53 +01:00 committed by GitHub
parent f8bd6c2dd5
commit c573503cbf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 38 additions and 3 deletions

View File

@ -440,4 +440,37 @@ mod tests {
vec![(&String::from("some command"), &String::from("files"))]
);
}
#[test]
fn test_shell_integration_keybindings_are_overwritten_by_user() {
let user_config = r#"
[shell_integration.keybindings]
"smart_autocomplete" = "ctrl-t"
"command_history" = "ctrl-["
"#;
let dir = tempdir().unwrap();
let config_dir = dir.path();
let config_file = config_dir.join(CONFIG_FILE_NAME);
let mut file = File::create(&config_file).unwrap();
file.write_all(user_config.as_bytes()).unwrap();
let config_env = ConfigEnv {
_data_dir: get_data_dir(),
config_dir: config_dir.to_path_buf(),
};
let config = Config::new(&config_env).unwrap();
assert_eq!(
config.shell_integration.keybindings,
[
(&String::from("command_history"), &String::from("ctrl-[")),
(&String::from("smart_autocomplete"), &String::from("ctrl-t"))
]
.iter()
.map(|(k, v)| ((*k).to_string(), (*v).to_string()))
.collect()
);
}
}

View File

@ -46,7 +46,9 @@ async fn main() -> Result<()> {
// optionally handle subcommands
debug!("Handling subcommands...");
args.command.as_ref().map(handle_subcommands);
args.command
.as_ref()
.map(|x| handle_subcommands(x, &config));
// optionally change the working directory
args.working_directory.as_ref().map(set_current_dir);
@ -112,7 +114,7 @@ pub fn set_current_dir(path: &String) -> Result<()> {
Ok(())
}
pub fn handle_subcommands(command: &Command) -> Result<()> {
pub fn handle_subcommands(command: &Command, config: &Config) -> Result<()> {
match command {
Command::ListChannels => {
list_channels();
@ -126,7 +128,7 @@ pub fn handle_subcommands(command: &Command) -> Result<()> {
let script = render_autocomplete_script_template(
target_shell,
completion_script(target_shell)?,
&Config::default().shell_integration,
&config.shell_integration,
)?;
println!("{script}");
exit(0);