diff --git a/CHANGELOG.md b/CHANGELOG.md index 5032f30..b560502 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 0.5.0 (2024-02-14) + +- Change `config.toml` `items.system` to `items.supported_systems` which + now accepts an array of strings instead of a string. This allows for + using a single template repo for setting both base16 and base24 + themes. + ## 0.4.0 (2024-02-11) - Enforces config.toml `[[items]]` `name` property is a unique value to diff --git a/Cargo.lock b/Cargo.lock index 5fc1b56..e417784 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -355,7 +355,7 @@ dependencies = [ [[package]] name = "tinty" -version = "0.4.0" +version = "0.5.0" dependencies = [ "anyhow", "clap", diff --git a/Cargo.toml b/Cargo.toml index 63e4502..fac4015 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "tinty" description = "Change the theme of your terminal, text editor and anything else with one command!" -version = "0.4.0" +version = "0.5.0" edition = "2021" license = "MIT" readme = "README.md" diff --git a/README.md b/README.md index 5577fa6..03531e9 100644 --- a/README.md +++ b/README.md @@ -102,23 +102,23 @@ required directories for data and configuration exist. #### `config.toml` -- `shell` - Add a shell command which will be used by tinty to execute +- `shell` \[String\] - Add a shell command which will be used by tinty to execute commands. This defaults to `sh -c '{}'`. If you want to use bash or zsh the format is similar `bash -c '{}'` and `zsh -c '{}'` -- `default_scheme` - defaults to `default-dark` -- `items` - A toml array of tables. Each item represents a template - - `name` (Required) - A unique value indicating the name of the item - - `path` (Required) - A url to the git repository or a path to a local +- `default_scheme` \[String\] - defaults to `default-dark` +- `items` \[Array<Item>\]- A toml array of tables. Each item represents a template + - `name` \[String\] (Required) - A unique value indicating the name of the item + - `path` \[String\] (Required) - A url to the git repository or a path to a local copy of the repository. It can start with `~/` which will map to your home directory, otherwise it must be an absolute path. - - `themes_dir` (Required) - The template directory name that contains + - `themes_dir` \[String\] (Required) - The template directory name that contains the theme files - - `hook` - A script that is executed after `tinty set ` + - `hook` \[String\]- A script that is executed after `tinty set ` has been run. `%f` can be used in the hook which is a variable name for the location of the theme file. `hook = ". %f"` will source the theme file after the theme has been set - - system - The scheme system of the template. Defaults to `base16`. - Currently supports `base16` and `base24` templates. + - `supported_systems` \[Array<String>\] - The scheme system of the template. Defaults to `\["base16"\]`. + Currently supports `"base16"` and `"base24"` templates. [Base16] and/or [Base24] templates are added to the `config.toml` file and Tinty will clone those repositories and the theme file when you run @@ -136,21 +136,21 @@ path = "https://github.com/tinted-theming/base16-shell" name = "shell" hook = ". %f" themes_dir = "scripts" -system = "base16" +supported_systems = ["base16"] [[items]] path = "~/projects/base16-tmux" name = "tmux" hook = "tmux source-file %f" themes_dir = "colors" -system = "base16" +supported_systems = ["base16"] [[items]] path = "/home/user/projects/base16-fzf" name = "fzf" hook = ". %f" themes_dir = "bash" -system = "base16" +supported_systems = ["base16"] ``` Once `tinty set ocean` is run, the following two files will be generated: diff --git a/license.html b/license.html index f0d1fdc..e9b0889 100644 --- a/license.html +++ b/license.html @@ -44,7 +44,7 @@

Third Party Licenses

Overview of licenses:

UNICODE, INC. LICENSE AGREEMENT - DATA FILES AND SOFTWARE
 
-See Terms of Use <https://www.unicode.org/copyright.html>
-for definitions of Unicode Inc.’s Data Files and Software.
+Unicode Data Files include all data files under the directories http://www.unicode.org/Public/, http://www.unicode.org/reports/, http://www.unicode.org/cldr/data/, http://source.icu-project.org/repos/icu/, and http://www.unicode.org/utility/trac/browser/.
+
+Unicode Data Files do not include PDF online code charts under the directory http://www.unicode.org/Public/.
 
-NOTICE TO USER: Carefully read the following legal agreement.
-BY DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING UNICODE INC.'S
-DATA FILES ("DATA FILES"), AND/OR SOFTWARE ("SOFTWARE"),
-YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE
-TERMS AND CONDITIONS OF THIS AGREEMENT.
-IF YOU DO NOT AGREE, DO NOT DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE
-THE DATA FILES OR SOFTWARE.
+Software includes any source code published in the Unicode Standard or under the directories http://www.unicode.org/Public/, http://www.unicode.org/reports/, http://www.unicode.org/cldr/data/, http://source.icu-project.org/repos/icu/, and http://www.unicode.org/utility/trac/browser/.
+
+NOTICE TO USER: Carefully read the following legal agreement. BY DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING UNICODE INC.'S DATA FILES ("DATA FILES"), AND/OR SOFTWARE ("SOFTWARE"), YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE TERMS AND CONDITIONS OF THIS AGREEMENT. IF YOU DO NOT AGREE, DO NOT DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE THE DATA FILES OR SOFTWARE.
 
 COPYRIGHT AND PERMISSION NOTICE
 
-Copyright © 1991-2022 Unicode, Inc. All rights reserved.
-Distributed under the Terms of Use in https://www.unicode.org/copyright.html.
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of the Unicode data files and any associated documentation
-(the "Data Files") or Unicode software and any associated documentation
-(the "Software") to deal in the Data Files or Software
-without restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, and/or sell copies of
-the Data Files or Software, and to permit persons to whom the Data Files
-or Software are furnished to do so, provided that either
-(a) this copyright and permission notice appear with all copies
-of the Data Files or Software, or
-(b) this copyright and permission notice appear in associated
-Documentation.
-
-THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF
-ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
-WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT OF THIRD PARTY RIGHTS.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS
-NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL
-DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
-DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
-TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-PERFORMANCE OF THE DATA FILES OR SOFTWARE.
-
-Except as contained in this notice, the name of a copyright holder
-shall not be used in advertising or otherwise to promote the sale,
-use or other dealings in these Data Files or Software without prior
-written authorization of the copyright holder.
+Copyright © 1991-2016 Unicode, Inc. All rights reserved. Distributed under the Terms of Use in http://www.unicode.org/copyright.html.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of the Unicode data files and any associated documentation (the "Data Files") or Unicode software and any associated documentation (the "Software") to deal in the Data Files or Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, and/or sell copies of the Data Files or Software, and to permit persons to whom the Data Files or Software are furnished to do so, provided that either
+
+     (a) this copyright and permission notice appear with all copies of the Data Files or Software, or
+     (b) this copyright and permission notice appear in associated Documentation.
+
+THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE DATA FILES OR SOFTWARE.
+
+Except as contained in this notice, the name of a copyright holder shall not be used in advertising or otherwise to promote the sale, use or other dealings in these Data Files or Software without prior written authorization of the copyright holder.
 
diff --git a/src/config.rs b/src/config.rs index b0ca820..10efa37 100644 --- a/src/config.rs +++ b/src/config.rs @@ -15,7 +15,7 @@ pub const BASE16_SHELL_REPO_NAME: &str = "base16-shell"; pub const BASE16_SHELL_THEMES_DIR: &str = "scripts"; pub const BASE16_SHELL_HOOK: &str = ". %f"; -#[derive(Debug, Default, Clone)] +#[derive(Debug, Default, Clone, PartialEq)] pub enum SupportedSchemeSystems { #[default] Base16, @@ -60,6 +60,14 @@ impl SupportedSchemeSystems { } } + pub fn from_str(system_string: &str) -> SupportedSchemeSystems { + match system_string { + "base16" => SupportedSchemeSystems::Base16, + "base24" => SupportedSchemeSystems::Base24, + _ => SupportedSchemeSystems::Base16, + } + } + pub fn variants() -> &'static [SupportedSchemeSystems] { static VARIANTS: &[SupportedSchemeSystems] = &[ SupportedSchemeSystems::Base16, @@ -76,13 +84,21 @@ pub struct ConfigItem { pub path: String, pub hook: Option, pub themes_dir: String, - pub system: Option, + pub supported_systems: Option>, } impl fmt::Display for ConfigItem { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let hook = self.hook.clone().unwrap_or_default(); - let system = self.system.clone().unwrap_or_default(); + let mut system_text = String::new(); + + for system in self + .supported_systems + .as_ref() + .unwrap_or(&vec![SupportedSchemeSystems::default()]) + { + system_text += system.to_str(); + } // You can format the output however you like writeln!(f, " - Item")?; @@ -91,7 +107,7 @@ impl fmt::Display for ConfigItem { if !hook.is_empty() { writeln!(f, " - hook: {}", hook)?; } - writeln!(f, " - system: {}", system.to_str())?; + writeln!(f, " - system: {}", system_text)?; writeln!(f, " - themes_dir: {}", self.themes_dir) } } @@ -137,7 +153,7 @@ impl Config { name: BASE16_SHELL_REPO_NAME.to_string(), themes_dir: BASE16_SHELL_THEMES_DIR.to_string(), hook: Some(BASE16_SHELL_HOOK.to_string()), - system: Some(SupportedSchemeSystems::Base16), // DEFAULT_SCHEME_SYSTEM + supported_systems: Some(vec![SupportedSchemeSystems::Base16]), // DEFAULT_SCHEME_SYSTEM }; // Add default `item` if no items exist @@ -153,8 +169,8 @@ impl Config { // Set default `system` property for missing systems if let Some(ref mut items) = config.items { for item in items.iter_mut() { - if item.system.is_none() { - item.system = Some(SupportedSchemeSystems::default()); + if item.supported_systems.is_none() { + item.supported_systems = Some(vec![SupportedSchemeSystems::default()]); } // Replace `~/` with absolute home path diff --git a/src/operations/set.rs b/src/operations/set.rs index 2a5fe79..a41e081 100644 --- a/src/operations/set.rs +++ b/src/operations/set.rs @@ -59,8 +59,8 @@ pub fn set(config_path: &Path, data_path: &Path, full_scheme_name: &str) -> Resu write_to_file(&data_path.join(CURRENT_SCHEME_FILE_NAME), full_scheme_name)?; // Collect config items that match the provided system - let system_items = items.iter().filter(|item| match &item.system { - Some(system) => system.to_str() == scheme_system, + let system_items = items.iter().filter(|item| match &item.supported_systems { + Some(supported_systems) => supported_systems.contains(&SupportedSchemeSystems::from_str(scheme_system)), None => false, }); @@ -71,8 +71,10 @@ pub fn set(config_path: &Path, data_path: &Path, full_scheme_name: &str) -> Resu if !themes_path.exists() { return Err(anyhow!(format!( - "Themes files are missing, try running `{} setup` or `{} update` and try again.", - REPO_NAME, REPO_NAME + "Provided theme path for {} does not exist: {}\nTry running `{} setup` or `{} update` or check your config.toml file and try again.", + item.name, + themes_path.display(), + REPO_NAME, REPO_NAME, ))); } @@ -121,8 +123,8 @@ pub fn set(config_path: &Path, data_path: &Path, full_scheme_name: &str) -> Resu } } None => println!( - "Theme does not exists for {}. Try running `{} update` or submit an issue on {}", - item.name, REPO_NAME, REPO_URL + "Theme does not exists for {} in {}. Try running `{} update` or submit an issue on {}", + item.name, themes_path.display(), REPO_NAME, REPO_URL ), } } diff --git a/src/utils.rs b/src/utils.rs index 3e8545d..a12d64a 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -124,11 +124,7 @@ pub fn git_diff(target_dir: &Path) -> Result { pub fn create_theme_filename_without_extension(item: &ConfigItem) -> Result { Ok(format!( - "{}-{}-{}-file", - item.system - .as_ref() - .unwrap_or(&SupportedSchemeSystems::default()) - .to_str(), + "{}-{}-file", item.name.clone(), item.themes_dir.clone().replace('/', "-"), // Flatten path/to/dir to path-to-dir )) diff --git a/tests/cli_set_subcommand_tests.rs b/tests/cli_set_subcommand_tests.rs index 1d01cd8..3a525ce 100644 --- a/tests/cli_set_subcommand_tests.rs +++ b/tests/cli_set_subcommand_tests.rs @@ -1,9 +1,9 @@ mod common; use crate::common::{cleanup, COMMAND_NAME, REPO_NAME}; -use anyhow::Result; +use anyhow::{Result, anyhow}; use std::fs; -use std::path::Path; +use std::path::{Path, PathBuf}; #[test] fn test_cli_set_subcommand_with_setup() -> Result<()> { @@ -19,6 +19,10 @@ fn test_cli_set_subcommand_with_setup() -> Result<()> { &scheme_name, ); let command_vec = shell_words::split(command.as_str()).map_err(anyhow::Error::new)?; + let system_data_path: PathBuf = + dirs::data_dir().ok_or_else(|| anyhow!("Error getting data directory"))?; + let data_dir = system_data_path.join(format!("tinted-theming/{}", REPO_NAME)); + let shell_theme_filename = "base16-shell-scripts-file.sh"; cleanup(config_path)?; fs::create_dir(config_path)?; @@ -35,6 +39,10 @@ fn test_cli_set_subcommand_with_setup() -> Result<()> { stdout.is_empty(), "stdout does not contain the expected output" ); + assert!( + data_dir.join(shell_theme_filename).exists(), + "Path does not exist" + ); cleanup(config_path)?; Ok(())