mirror of
https://github.com/alexpasmantier/television.git
synced 2025-06-06 19:45:23 +00:00
fix(config): make user shell integration trigger configuration override defaults entirely (#417)
Fixes #374
This commit is contained in:
parent
05bd64afe9
commit
731bc7ee80
@ -157,19 +157,23 @@ impl Config {
|
|||||||
mut default: Config,
|
mut default: Config,
|
||||||
mut user: Config,
|
mut user: Config,
|
||||||
) -> Config {
|
) -> Config {
|
||||||
// merge shell integration fallback channel with default fallback channel
|
// use default fallback channel as a fallback if user hasn't specified one
|
||||||
if user.shell_integration.fallback_channel.is_empty() {
|
if user.shell_integration.fallback_channel.is_empty() {
|
||||||
user.shell_integration
|
user.shell_integration
|
||||||
.fallback_channel
|
.fallback_channel
|
||||||
.clone_from(&default.shell_integration.fallback_channel);
|
.clone_from(&default.shell_integration.fallback_channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
// merge shell integration triggers with commands
|
// merge shell integration triggers with commands
|
||||||
default.shell_integration.merge_triggers();
|
default.shell_integration.merge_triggers();
|
||||||
user.shell_integration.merge_triggers();
|
user.shell_integration.merge_triggers();
|
||||||
// merge shell integration commands with default commands
|
// merge shell integration commands with default commands
|
||||||
let mut merged_commands = default.shell_integration.commands.clone();
|
if user.shell_integration.commands.is_empty() {
|
||||||
merged_commands.extend(user.shell_integration.commands.clone());
|
user.shell_integration
|
||||||
user.shell_integration.commands = merged_commands;
|
.commands
|
||||||
|
.clone_from(&default.shell_integration.commands);
|
||||||
|
}
|
||||||
|
|
||||||
// merge shell integration keybindings with default keybindings
|
// merge shell integration keybindings with default keybindings
|
||||||
let mut merged_keybindings =
|
let mut merged_keybindings =
|
||||||
default.shell_integration.keybindings.clone();
|
default.shell_integration.keybindings.clone();
|
||||||
@ -388,10 +392,6 @@ mod tests {
|
|||||||
map
|
map
|
||||||
});
|
});
|
||||||
|
|
||||||
default_config
|
|
||||||
.shell_integration
|
|
||||||
.commands
|
|
||||||
.extend(vec![("git add".to_string(), "git-diff".to_string())]);
|
|
||||||
default_config
|
default_config
|
||||||
.shell_integration
|
.shell_integration
|
||||||
.keybindings
|
.keybindings
|
||||||
@ -404,11 +404,40 @@ mod tests {
|
|||||||
assert_eq!(config.previewers, default_config.previewers);
|
assert_eq!(config.previewers, default_config.previewers);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
config.shell_integration.commands,
|
config.shell_integration.commands,
|
||||||
default_config.shell_integration.commands
|
[(&String::from("git add"), &String::from("git-diff"))]
|
||||||
|
.iter()
|
||||||
|
.map(|(k, v)| ((*k).to_string(), (*v).to_string()))
|
||||||
|
.collect()
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
config.shell_integration.keybindings,
|
config.shell_integration.keybindings,
|
||||||
default_config.shell_integration.keybindings
|
default_config.shell_integration.keybindings
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_setting_user_shell_integration_triggers_overrides_default() {
|
||||||
|
let user_config = r#"
|
||||||
|
[shell_integration.channel_triggers]
|
||||||
|
"files" = ["some command"]
|
||||||
|
"#;
|
||||||
|
|
||||||
|
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.commands.iter().collect::<Vec<_>>(),
|
||||||
|
vec![(&String::from("some command"), &String::from("files"))]
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user