From 931ef153259a03f831ae4f061007d7d9ac651479 Mon Sep 17 00:00:00 2001 From: Christian Friedow Date: Wed, 29 May 2024 20:42:14 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20implement=20gitmoji=20plugin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 23 ++- client/src/main.rs | 6 + client/src/plugin/gitmoji.rs | 378 +++++++++++++++++++++++++++++++++++ client/src/plugin/mod.rs | 1 + client/src/settings.rs | 18 ++ 5 files changed, 425 insertions(+), 1 deletion(-) create mode 100644 client/src/plugin/gitmoji.rs diff --git a/README.md b/README.md index 3269ec4..4cbb1da 100644 --- a/README.md +++ b/README.md @@ -119,8 +119,9 @@ To avoid delays in the plugin launch time this plugin comes with a systemd servi This index file is located at `~/.cache/centerpiece/git-repositories-index.json` and necessary for the plugin to work. It exports the following environment variables: + - `$GIT_DIRECTORY`: The path to the git directory. -- `$GIT_DIRECTORY_NAME`: The name of the git directory. +- `$GIT_DIRECTORY_NAME`: The name of the git directory. If `zoxide` integration is enabled, the plugin will sort your projects based on their respective `zoxide` scores. @@ -137,6 +138,21 @@ plugin: - ["alacritty", "--working-directory", "$GIT_DIRECTORY" "--class" "$GIT_DIRECTORY_NAME"] ``` +### Gitmoji + +_List gitmojis and copy them._ + +Note: You need to have [wl-clipboard](https://github.com/bugaevc/wl-clipboard) installed on your system. + +**Related config keys** + +```yml +# ~/.config/centerpiece/config.yml +plugin: + gitmoji: + enable: false +``` + ### System Commands _Lock, sleep, restart or shutdown your system._ @@ -235,6 +251,8 @@ You can specify alternative configuration locations through: commands: - ["alacritty", "--command", "nvim", "$GIT_DIRECTORY"] - ["alacritty", "--working-directory", "$GIT_DIRECTORY"] + gitmoji: + enable: false resource_monitor_battery: enable: true resource_monitor_cpu: @@ -287,6 +305,9 @@ You can specify alternative configuration locations through: ["alacritty" "--working-directory" "$GIT_DIRECTORY"] ]; }; + gitmoji: { + enable = false; + }; resource_monitor_battery = { enable = true; }; diff --git a/client/src/main.rs b/client/src/main.rs index 268f0e1..0d4ac18 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -189,6 +189,12 @@ impl Application for Centerpiece { >()); } + if self.settings.plugin.gitmoji.enable { + subscriptions.push(crate::plugin::utils::spawn::< + crate::plugin::gitmoji::GitmojiPlugin, + >()); + } + if self.settings.plugin.resource_monitor_battery.enable { subscriptions.push(crate::plugin::utils::spawn::< crate::plugin::resource_monitor::battery::BatteryPlugin, diff --git a/client/src/plugin/gitmoji.rs b/client/src/plugin/gitmoji.rs new file mode 100644 index 0000000..ae7c687 --- /dev/null +++ b/client/src/plugin/gitmoji.rs @@ -0,0 +1,378 @@ +use crate::plugin::utils::Plugin; +use anyhow::Context; + +struct Gitmoji { + emoji: String, + description: String, +} +fn gitmojis() -> Vec { + vec![ + Gitmoji { + emoji: String::from("๐ŸŽจ"), + description: String::from("๐ŸŽจ Improve structure / format of the code."), + }, + Gitmoji { + emoji: String::from("โšก๏ธ"), + description: String::from("โšก๏ธ Improve performance."), + }, + Gitmoji { + emoji: String::from("๐Ÿ”ฅ"), + description: String::from("๐Ÿ”ฅ Remove code or files."), + }, + Gitmoji { + emoji: String::from("๐Ÿ›"), + description: String::from("๐Ÿ› Fix a bug."), + }, + Gitmoji { + emoji: String::from("๐Ÿš‘๏ธ"), + description: String::from("๐Ÿš‘๏ธ Critical hotfix."), + }, + Gitmoji { + emoji: String::from("โœจ"), + description: String::from("โœจ Introduce new features."), + }, + Gitmoji { + emoji: String::from("๐Ÿ“"), + description: String::from("๐Ÿ“ Add or update documentation."), + }, + Gitmoji { + emoji: String::from("๐Ÿš€"), + description: String::from("๐Ÿš€ Deploy stuff."), + }, + Gitmoji { + emoji: String::from("๐Ÿ’„"), + description: String::from("๐Ÿ’„ Add or update the UI and style files."), + }, + Gitmoji { + emoji: String::from("๐ŸŽ‰"), + description: String::from("๐ŸŽ‰ Begin a project."), + }, + Gitmoji { + emoji: String::from("โœ…"), + description: String::from("โœ… Add, update, or pass tests."), + }, + Gitmoji { + emoji: String::from("๐Ÿ”’๏ธ"), + description: String::from("๐Ÿ”’๏ธ Fix security or privacy issues."), + }, + Gitmoji { + emoji: String::from("๐Ÿ”"), + description: String::from("๐Ÿ” Add or update secrets."), + }, + Gitmoji { + emoji: String::from("๐Ÿ”–"), + description: String::from("๐Ÿ”– Release / Version tags."), + }, + Gitmoji { + emoji: String::from("๐Ÿšจ"), + description: String::from("๐Ÿšจ Fix compiler / linter warnings."), + }, + Gitmoji { + emoji: String::from("๐Ÿšง"), + description: String::from("๐Ÿšง Work in progress."), + }, + Gitmoji { + emoji: String::from("๐Ÿ’š"), + description: String::from("๐Ÿ’š Fix CI Build."), + }, + Gitmoji { + emoji: String::from("โฌ‡๏ธ"), + description: String::from("โฌ‡๏ธ Downgrade dependencies."), + }, + Gitmoji { + emoji: String::from("โฌ†๏ธ"), + description: String::from("โฌ†๏ธ Upgrade dependencies."), + }, + Gitmoji { + emoji: String::from("๐Ÿ“Œ"), + description: String::from("๐Ÿ“Œ Pin dependencies to specific versions."), + }, + Gitmoji { + emoji: String::from("๐Ÿ‘ท"), + description: String::from("๐Ÿ‘ท Add or update CI build system."), + }, + Gitmoji { + emoji: String::from("๐Ÿ“ˆ"), + description: String::from("๐Ÿ“ˆ Add or update analytics or track code."), + }, + Gitmoji { + emoji: String::from("โ™ป๏ธ"), + description: String::from("โ™ป๏ธ Refactor code."), + }, + Gitmoji { + emoji: String::from("โž•"), + description: String::from("โž• Add a dependency."), + }, + Gitmoji { + emoji: String::from("โž–"), + description: String::from("โž– Remove a dependency."), + }, + Gitmoji { + emoji: String::from("๐Ÿ”ง"), + description: String::from("๐Ÿ”ง Add or update configuration files."), + }, + Gitmoji { + emoji: String::from("๐Ÿ”จ"), + description: String::from("๐Ÿ”จ Add or update development scripts."), + }, + Gitmoji { + emoji: String::from("๐ŸŒ"), + description: String::from("๐ŸŒ Internationalization and localization."), + }, + Gitmoji { + emoji: String::from("โœ๏ธ"), + description: String::from("โœ๏ธ Fix typos."), + }, + Gitmoji { + emoji: String::from("๐Ÿ’ฉ"), + description: String::from("๐Ÿ’ฉ Write bad code that needs to be improved."), + }, + Gitmoji { + emoji: String::from("โช๏ธ"), + description: String::from("โช๏ธ Revert changes."), + }, + Gitmoji { + emoji: String::from("๐Ÿ”€"), + description: String::from("๐Ÿ”€ Merge branches."), + }, + Gitmoji { + emoji: String::from("๐Ÿ“ฆ๏ธ"), + description: String::from("๐Ÿ“ฆ๏ธ Add or update compiled files or packages."), + }, + Gitmoji { + emoji: String::from("๐Ÿ‘ฝ๏ธ"), + description: String::from("๐Ÿ‘ฝ๏ธ Update code due to external API changes."), + }, + Gitmoji { + emoji: String::from("๐Ÿšš"), + description: String::from("๐Ÿšš Move or rename resources (e.g.): files, paths, routes)."), + }, + Gitmoji { + emoji: String::from("๐Ÿ“„"), + description: String::from("๐Ÿ“„ Add or update license."), + }, + Gitmoji { + emoji: String::from("๐Ÿ’ฅ"), + description: String::from("๐Ÿ’ฅ Introduce breaking changes."), + }, + Gitmoji { + emoji: String::from("๐Ÿฑ"), + description: String::from("๐Ÿฑ Add or update assets."), + }, + Gitmoji { + emoji: String::from("โ™ฟ๏ธ"), + description: String::from("โ™ฟ๏ธ Improve accessibility."), + }, + Gitmoji { + emoji: String::from("๐Ÿ’ก"), + description: String::from("๐Ÿ’ก Add or update comments in source code."), + }, + Gitmoji { + emoji: String::from("๐Ÿป"), + description: String::from("๐Ÿป Write code drunkenly."), + }, + Gitmoji { + emoji: String::from("๐Ÿ’ฌ"), + description: String::from("๐Ÿ’ฌ Add or update text and literals."), + }, + Gitmoji { + emoji: String::from("๐Ÿ—ƒ๏ธ"), + description: String::from("๐Ÿ—ƒ๏ธ Perform database related changes."), + }, + Gitmoji { + emoji: String::from("๐Ÿ”Š"), + description: String::from("๐Ÿ”Š Add or update logs."), + }, + Gitmoji { + emoji: String::from("๐Ÿ”‡"), + description: String::from("๐Ÿ”‡ Remove logs."), + }, + Gitmoji { + emoji: String::from("๐Ÿ‘ฅ"), + description: String::from("๐Ÿ‘ฅ Add or update contributor(s)."), + }, + Gitmoji { + emoji: String::from("๐Ÿšธ"), + description: String::from("๐Ÿšธ Improve user experience / usability."), + }, + Gitmoji { + emoji: String::from("๐Ÿ—๏ธ"), + description: String::from("๐Ÿ—๏ธ Make architectural changes."), + }, + Gitmoji { + emoji: String::from("๐Ÿ“ฑ"), + description: String::from("๐Ÿ“ฑ Work on responsive design."), + }, + Gitmoji { + emoji: String::from("๐Ÿคก"), + description: String::from("๐Ÿคก Mock things."), + }, + Gitmoji { + emoji: String::from("๐Ÿฅš"), + description: String::from("๐Ÿฅš Add or update an easter egg."), + }, + Gitmoji { + emoji: String::from("๐Ÿ™ˆ"), + description: String::from("๐Ÿ™ˆ Add or update a .gitignore file."), + }, + Gitmoji { + emoji: String::from("๐Ÿ“ธ"), + description: String::from("๐Ÿ“ธ Add or update snapshots."), + }, + Gitmoji { + emoji: String::from("โš—๏ธ"), + description: String::from("โš—๏ธ Perform experiments."), + }, + Gitmoji { + emoji: String::from("๐Ÿ”๏ธ"), + description: String::from("๐Ÿ”๏ธ Improve SEO."), + }, + Gitmoji { + emoji: String::from("๐Ÿท๏ธ"), + description: String::from("๐Ÿท๏ธ Add or update types."), + }, + Gitmoji { + emoji: String::from("๐ŸŒฑ"), + description: String::from("๐ŸŒฑ Add or update seed files."), + }, + Gitmoji { + emoji: String::from("๐Ÿšฉ"), + description: String::from("๐Ÿšฉ Add, update, or remove feature flags."), + }, + Gitmoji { + emoji: String::from("๐Ÿฅ…"), + description: String::from("๐Ÿฅ… Catch errors."), + }, + Gitmoji { + emoji: String::from("๐Ÿ’ซ"), + description: String::from("๐Ÿ’ซ Add or update animations and transitions."), + }, + Gitmoji { + emoji: String::from("๐Ÿ—‘๏ธ"), + description: String::from("๐Ÿ—‘๏ธ Deprecate code that needs to be cleaned up."), + }, + Gitmoji { + emoji: String::from("๐Ÿ›‚"), + description: String::from( + "๐Ÿ›‚ Work on code related to authorization, roles and permissions.", + ), + }, + Gitmoji { + emoji: String::from("๐Ÿฉน"), + description: String::from("๐Ÿฉน Simple fix for a non-critical issue."), + }, + Gitmoji { + emoji: String::from("๐Ÿง"), + description: String::from("๐Ÿง Data exploration/inspection."), + }, + Gitmoji { + emoji: String::from("โšฐ๏ธ"), + description: String::from("โšฐ๏ธ Remove dead code."), + }, + Gitmoji { + emoji: String::from("๐Ÿงช"), + description: String::from("๐Ÿงช Add a failing test."), + }, + Gitmoji { + emoji: String::from("๐Ÿ‘”"), + description: String::from("๐Ÿ‘” Add or update business logic."), + }, + Gitmoji { + emoji: String::from("๐Ÿฉบ"), + description: String::from("๐Ÿฉบ Add or update healthcheck."), + }, + Gitmoji { + emoji: String::from("๐Ÿงฑ"), + description: String::from("๐Ÿงฑ Infrastructure related changes."), + }, + Gitmoji { + emoji: String::from("๐Ÿง‘โ€๐Ÿ’ป"), + description: String::from("๐Ÿง‘โ€๐Ÿ’ป Improve developer experience."), + }, + Gitmoji { + emoji: String::from("๐Ÿ’ธ"), + description: String::from("๐Ÿ’ธ Add sponsorships or money related infrastructure."), + }, + Gitmoji { + emoji: String::from("๐Ÿงต"), + description: String::from( + "๐Ÿงต Add or update code related to multithreading or concurrency.", + ), + }, + Gitmoji { + emoji: String::from("๐Ÿฆบ"), + description: String::from("๐Ÿฆบ Add or update code related to validation."), + }, + ] +} + +pub struct GitmojiPlugin { + entries: Vec, +} + +impl Plugin for GitmojiPlugin { + fn new() -> Self { + Self { entries: vec![] } + } + + fn id() -> &'static str { + "gitmoji" + } + + fn priority() -> u32 { + 13 + } + + fn title() -> &'static str { + "๓ฐž… Gitmoji" + } + + fn update_entries(&mut self) -> anyhow::Result<()> { + self.entries.clear(); + + let entries = gitmojis() + .iter() + .map(|gitmoji| crate::model::Entry { + id: gitmoji.emoji.clone(), + title: gitmoji.description.clone(), + action: String::from("copy"), + meta: String::from("Gitmoji"), + command: None, + }) + .collect(); + + self.set_entries(entries); + Ok(()) + } + + fn entries(&self) -> Vec { + self.entries.clone() + } + + fn set_entries(&mut self, entries: Vec) { + self.entries = entries; + } + + fn activate( + &mut self, + entry: crate::model::Entry, + plugin_channel_out: &mut iced::futures::channel::mpsc::Sender, + ) -> anyhow::Result<()> { + std::process::Command::new("wl-copy") + .arg(&entry.id) + .spawn() + .context(format!( + "Failed to copy gitmoji while activating entry with id '{}'.", + entry.id + ))?; + + plugin_channel_out + .try_send(crate::Message::Exit) + .context(format!( + "Failed to send message to exit application while activating entry with id '{}'.", + entry.id + ))?; + + Ok(()) + } +} diff --git a/client/src/plugin/mod.rs b/client/src/plugin/mod.rs index 6e40d5a..597c42f 100644 --- a/client/src/plugin/mod.rs +++ b/client/src/plugin/mod.rs @@ -2,6 +2,7 @@ pub mod applications; pub mod brave; pub mod clock; pub mod git_repositories; +pub mod gitmoji; pub mod resource_monitor; pub mod sway_windows; pub mod system; diff --git a/client/src/settings.rs b/client/src/settings.rs index 2337966..743a57d 100644 --- a/client/src/settings.rs +++ b/client/src/settings.rs @@ -17,6 +17,10 @@ fn default_true() -> bool { true } +fn default_false() -> bool { + false +} + #[derive(Debug, Deserialize)] pub struct ApplicationsPluginSettings { #[serde(default = "default_true")] @@ -130,6 +134,18 @@ impl Default for GitRepositoriesPluginSettings { } } +#[derive(Debug, Deserialize)] +pub struct GitmojiPluginSettings { + #[serde(default = "default_false")] + pub enable: bool, +} + +impl Default for GitmojiPluginSettings { + fn default() -> Self { + Self { enable: false } + } +} + #[derive(Debug, Deserialize)] pub struct ResourceMonitorBatteryPluginSettings { #[serde(default = "default_true")] @@ -229,6 +245,8 @@ pub struct PluginSettings { #[serde(default)] pub git_repositories: GitRepositoriesPluginSettings, #[serde(default)] + pub gitmoji: GitmojiPluginSettings, + #[serde(default)] pub resource_monitor_battery: ResourceMonitorBatteryPluginSettings, #[serde(default)] pub resource_monitor_cpu: ResourceMonitorCpuPluginSettings,