Skip to content

Commit

Permalink
vivid: add module
Browse files Browse the repository at this point in the history
  • Loading branch information
arunoruto committed Nov 6, 2024
1 parent 2f607e0 commit 2b9f396
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ let
./programs/vifm.nix
./programs/vim-vint.nix
./programs/vim.nix
./programs/vivid.nix
./programs/vscode.nix
./programs/vscode/haskell.nix
./programs/pywal.nix
Expand Down
141 changes: 141 additions & 0 deletions modules/programs/vivid.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
{ config, lib, pkgs, ... }:
let
yaml = pkgs.formats.yaml { };
bashLine = theme:
''export LS_COLORS="$(${lib.getExe pkgs.vivid} generate ${theme})"'';
fishLine = theme:
"set -gx LS_COLORS (${lib.getExe pkgs.vivid} generate ${theme})";
nushellLine = theme: "${lib.getExe pkgs.vivid} generate ${theme}";
zshLine = bashLine;
in {
meta.maintainers = [ lib.maintainers.arunoruto ];

options.programs.vivid = {
enable = lib.mkEnableOption ''
vivid - A themeable LS_COLORS generator with a rich filetype datebase
<link xlink:href="https://github.com/sharkdp/vivid" />
'';

package = lib.mkPackageOption pkgs "vivid" { };

enableBashIntegration = lib.mkOption {
default = true;
type = lib.types.bool;
description = ''
Whether to enable Bash integration.
Adds `${bashLine "<theme>"}` to Bash.
'';
};

enableFishIntegration = lib.mkOption {
default = true;
type = lib.types.bool;
description = ''
Whether to enable Fish integration.
Adds `${fishLine "<theme>"}` to Fish.
'';
};

enableNushellIntegration = lib.mkOption {
default = true;
type = lib.types.bool;
description = ''
Whether to enable Nushell integration.
Adds `${nushellLine "<theme>"}` to Nushell.
'';
};

enableZshIntegration = lib.mkOption {
default = true;
type = lib.types.bool;
description = ''
Whether to enable Zsh integration.
Adds `${zshLine "<theme>"}` to Zsh.
'';
};

theme = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
example = "molokai";
description = ''
Color theme to enable.
Run `vivid themes` for a list of available themes.
'';
};

filetypes = lib.mkOption {
type = yaml.type;
default = { };
example = lib.literalExample ''
{
core = {
regular_file = [ "$fi" ];
directory = [ "$di" ];
};
text = {
readme = [ "README.md" ];
licenses = [ "LICENSE" ];
};
}
'';
description = ''
Configuration written to
<filename>~/.config/vivid/filetypes.yml</filename>.
Visit <link xlink:href="https://github.com/sharkdp/vivid/tree/master/config/filetypes.yml" />
for a reference file.
'';
};

themes = lib.mkOption {
type = lib.types.attrsOf (yaml.type);
default = { };
example = lib.literalExample ''
{
mytheme = {
colors = {
blue = "0000ff";
};
core = {
directory = {
foreground = "blue";
font-style = "bold";
};
};
};
}
'';
description = ''
Theme files written to
<filename>~/.config/vivid/themes/<mytheme>.yml</filename>.
Visit <link xlink:href="https://github.com/sharkdp/vivid/tree/master/themes" />
for references.
'';
};
};

config = let cfg = config.programs.vivid;
in lib.mkIf cfg.enable {
home.packages = [ cfg.package ];

programs.bash.initExtra =
lib.mkIf cfg.enableBashIntegration (bashLine cfg.theme);
programs.fish.interactiveShellInit =
lib.mkIf cfg.enableFishIntegration (fishLine cfg.theme);
programs.nushell.environmentVariables.LS_COLORS =
lib.mkIf cfg.enableNushellIntegration
(lib.hm.nushell.mkNushellInline (nushellLine cfg.theme));
programs.zsh.initExtra =
lib.mkIf cfg.enableZshIntegration (zshLine cfg.theme);

xdg.configFile = {
"vivid/filetypes.yml" =
lib.mkIf (builtins.length (builtins.attrNames cfg.filetypes) > 0) {
source = yaml.generate "filetypes.yml" cfg.filetypes;
};
} // lib.mapAttrs' (name: value:
lib.nameValuePair "vivid/themes/${name}.yml" {
source = yaml.generate "${name}.yml" value;
}) cfg.themes;
};
}

0 comments on commit 2b9f396

Please sign in to comment.