From 844336ceb2e9c3b3509dda3a0b7917bbc8f7a08e Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Sun, 29 Sep 2024 09:19:31 -0500 Subject: [PATCH] plugins/web-devicons: support custom icons and default icon --- plugins/by-name/web-devicons/default.nix | 34 ++++++++++++++- .../plugins/by-name/web-devicons/default.nix | 42 +++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/plugins/by-name/web-devicons/default.nix b/plugins/by-name/web-devicons/default.nix index b3ab1072..4b657342 100644 --- a/plugins/by-name/web-devicons/default.nix +++ b/plugins/by-name/web-devicons/default.nix @@ -1,6 +1,6 @@ { lib, ... }: let - inherit (lib.nixvim) defaultNullOpts; + inherit (lib.nixvim) defaultNullOpts mkNullOrOption toLuaObject; in lib.nixvim.neovim-plugin.mkNeovimPlugin { name = "web-devicons"; @@ -14,4 +14,36 @@ lib.nixvim.neovim-plugin.mkNeovimPlugin { color_icons = true; strict = true; }; + + extraOptions = { + customIcons = defaultNullOpts.mkAttrsOf (lib.types.submodule { + freeformType = lib.types.anything; + + options = { + icon = defaultNullOpts.mkStr null "Icon to use."; + color = defaultNullOpts.mkStr null "Color of the icon."; + cterm_color = defaultNullOpts.mkStr null "Cterm color of the icon."; + name = defaultNullOpts.mkStr null "Name to replace with icon."; + }; + }) { } ''Custom overrides for icons.''; + + defaultIcon = mkNullOrOption (lib.types.submodule { + options = { + icon = defaultNullOpts.mkStr null "Icon to use."; + color = defaultNullOpts.mkStr null "Color of the icon."; + cterm_color = defaultNullOpts.mkStr null "Cterm color of the icon."; + }; + }) ''Set the default icon when none is found.''; + }; + + extraConfig = cfg: { + plugins.web-devicons.luaConfig.post = + lib.optionalString (cfg.customIcons != null) '' + require('nvim-web-devicons').set_icon(${toLuaObject cfg.customIcons}) + '' + + lib.optionalString (cfg.defaultIcon != null) '' + require('nvim-web-devicons').set_default_icon( + ${toLuaObject cfg.defaultIcon.icon}, ${toLuaObject cfg.defaultIcon.color}, ${toLuaObject cfg.defaultIcon.cterm_color}) + ''; + }; } diff --git a/tests/test-sources/plugins/by-name/web-devicons/default.nix b/tests/test-sources/plugins/by-name/web-devicons/default.nix index 6b223baf..1b91c540 100644 --- a/tests/test-sources/plugins/by-name/web-devicons/default.nix +++ b/tests/test-sources/plugins/by-name/web-devicons/default.nix @@ -2,4 +2,46 @@ empty = { plugins.web-devicons.enable = true; }; + + custom-icons = { + plugins.web-devicons = { + enable = true; + + customIcons = { + lir_folder_icon = { + icon = ""; + color = "#7ebae4"; + name = "LirFolderNode"; + }; + zsh = { + icon = ""; + color = "#428850"; + cterm_color = "65"; + name = "Zsh"; + }; + }; + }; + }; + + default-icon = { + plugins.web-devicons = { + enable = true; + + defaultIcon = { + icon = ""; + color = "#7ebae4"; + cterm_color = "65"; + }; + }; + }; + + default-icon-no-color = { + plugins.web-devicons = { + enable = true; + + defaultIcon = { + icon = ""; + }; + }; + }; }