Skip to content

Commit

Permalink
plugins/web-devicons: support custom icons and default icon
Browse files Browse the repository at this point in the history
  • Loading branch information
khaneliman committed Sep 29, 2024
1 parent 4e2a022 commit 844336c
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
34 changes: 33 additions & 1 deletion plugins/by-name/web-devicons/default.nix
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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})
'';
};
}
42 changes: 42 additions & 0 deletions tests/test-sources/plugins/by-name/web-devicons/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
};
};
};
}

0 comments on commit 844336c

Please sign in to comment.