Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: File-extension #32

Merged
merged 11 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions fixtures/schemes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ base16-mellow-purple
base16-mexico-light
base16-mocha
base16-monokai
base16-moonlight
base16-mountain
base16-nebula
base16-nord-light
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ pub struct ConfigItem {
pub themes_dir: String,
#[serde(rename = "supported-systems")]
pub supported_systems: Option<Vec<SupportedSchemeSystems>>,
#[serde(rename = "theme-file-extension")]
pub theme_file_extension: Option<String>,
}

impl fmt::Display for ConfigItem {
Expand Down Expand Up @@ -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
Expand Down
17 changes: 13 additions & 4 deletions src/operations/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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])
Expand Down
Loading