diff --git a/fixtures/schemes.txt b/fixtures/schemes.txt index ced5ea3..6796ec6 100644 --- a/fixtures/schemes.txt +++ b/fixtures/schemes.txt @@ -155,6 +155,7 @@ base16-mellow-purple base16-mexico-light base16-mocha base16-monokai +base16-moonlight base16-mountain base16-nebula base16-nord-light @@ -177,6 +178,10 @@ base16-pico base16-pinky base16-pop base16-porple +base16-precious-dark-eleven +base16-precious-dark-fifteen +base16-precious-light-warm +base16-precious-light-white base16-primer-dark-dimmed base16-primer-dark base16-primer-light diff --git a/src/config.rs b/src/config.rs index ba5b3d3..c9737c9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -93,6 +93,8 @@ pub struct ConfigItem { pub themes_dir: String, #[serde(rename = "supported-systems")] pub supported_systems: Option>, + #[serde(rename = "theme-file-extension")] + pub theme_file_extension: Option, } impl fmt::Display for ConfigItem { @@ -171,6 +173,7 @@ impl Config { themes_dir: BASE16_SHELL_THEMES_DIR.to_string(), hook: Some(BASE16_SHELL_HOOK.to_string()), supported_systems: Some(vec![SupportedSchemeSystems::Base16]), // DEFAULT_SCHEME_SYSTEM + theme_file_extension: None, }; // Add default `item` if no items exist diff --git a/src/operations/apply.rs b/src/operations/apply.rs index 5afe221..1111f8f 100644 --- a/src/operations/apply.rs +++ b/src/operations/apply.rs @@ -86,9 +86,16 @@ pub fn apply(config_path: &Path, data_path: &Path, full_scheme_name: &str) -> Re .with_context(|| format!("Themes are missing from {}, try running `{} install` or `{} update` and try again.", item.name, REPO_NAME, REPO_NAME))?; let theme_option = &theme_dir.filter_map(Result::ok).find(|entry| { let path = entry.path(); - let filename = path.file_stem().and_then(|name| name.to_str()); - - full_scheme_name == filename.unwrap_or_default() + match &item.theme_file_extension { + Some(extension) => { + let filename = path.file_name().and_then(|name| name.to_str()); + format!("{}{}", full_scheme_name, extension) == filename.unwrap_or_default() + } + None => { + let filename = path.file_stem().and_then(|name| name.to_str()); + full_scheme_name == filename.unwrap_or_default() + } + } }); // Copy that theme to the data_path or log a message that it isn't found @@ -113,7 +120,9 @@ pub fn apply(config_path: &Path, data_path: &Path, full_scheme_name: &str) -> Re // Run hook for item if provided if let Some(hook_text) = &item.hook { let hook_script = - hook_text.replace("%f", format!("\"{}\"", data_theme_path.display()).as_str()); + hook_text + .replace("%f", format!("\"{}\"", data_theme_path.display()).as_str()) + .replace("%n", full_scheme_name); let command_vec = get_shell_command_from_string(config_path, hook_script.as_str())?; Command::new(&command_vec[0]) diff --git a/tests/cli_apply_subcommand_tests.rs b/tests/cli_apply_subcommand_tests.rs index 9a75fd7..0b73403 100644 --- a/tests/cli_apply_subcommand_tests.rs +++ b/tests/cli_apply_subcommand_tests.rs @@ -240,3 +240,50 @@ hook = "echo \"path: %f\"" cleanup()?; Ok(()) } + +#[test] +fn test_cli_apply_subcommand_with_config_theme_file_extension() -> Result<()> { + // ------- + // Arrange + // ------- + let scheme_name = "base16-uwunicorn"; + let (config_path, data_path, command_vec, cleanup) = setup( + "test_cli_apply_subcommand_with_custom_schemes", + format!("apply {}", &scheme_name).as_str(), + )?; + let config_content = r#" +[[items]] +path = "https://github.com/tinted-theming/tinted-alacritty" +name = "tinted-alacritty" +themes-dir = "colors" +hook = "echo \"expected alacritty output: %n\"" + +[[items]] +name = "base16-emacs" +path = "https://github.com/tinted-theming/base16-emacs" +theme-file-extension="-theme.el" +themes-dir="build" +hook = "echo \"expected emacs output: %n\"" +"#; + let expected_output = + "expected alacritty output: base16-uwunicorn\nexpected emacs output: base16-uwunicorn\n"; + write_to_file(&config_path, config_content)?; + + // --- + // Act + // --- + utils::run_install_command(&config_path, &data_path)?; + let (stdout, stderr) = utils::run_command(command_vec).unwrap(); + + // ------ + // Assert + // ------ + assert_eq!(stdout, expected_output,); + assert!( + stderr.is_empty(), + "stderr does not contain the expected output" + ); + + cleanup()?; + Ok(()) +}