mirror of
https://github.com/alexpasmantier/television.git
synced 2025-06-06 19:45:23 +00:00
fix(config): fix shell integration keybindings not overwriting defaults (#431)
Fixes #430
This commit is contained in:
parent
f8bd6c2dd5
commit
c573503cbf
@ -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()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user