From 3a5cd906319506e77026787067bb348fbb3ef066 Mon Sep 17 00:00:00 2001 From: Lisa Ugray Date: Tue, 21 Apr 2020 15:26:20 -0400 Subject: [PATCH] bat: add custom themes Add the ability to add custom theme files to bat. Co-Authored-By: Robert Helgesson --- modules/programs/bat.nix | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/modules/programs/bat.nix b/modules/programs/bat.nix index aa0df9abd..e2b30ea93 100644 --- a/modules/programs/bat.nix +++ b/modules/programs/bat.nix @@ -24,14 +24,35 @@ in { ''; }; + themes = mkOption { + type = types.attrsOf types.lines; + default = { }; + example = literalExample '' + { + dracula = builtins.readFile (pkgs.fetchFromGitHub { + owner = "dracula"; + repo = "sublime"; # Bat uses sublime syntax for its themes + rev = "26c57ec282abcaa76e57e055f38432bd827ac34e"; + sha256 = "019hfl4zbn4vm4154hh3bwk6hm7bdxbr1hdww83nabxwjn99ndhv"; + } + "/Dracula.tmTheme"); + } + ''; + description = '' + Additional themes to provide. + ''; + }; + }; config = mkIf cfg.enable { home.packages = [ pkgs.bat ]; - xdg.configFile."bat/config" = mkIf (cfg.config != { }) { - text = concatStringsSep "\n" - (mapAttrsToList (n: v: ''--${n}="${v}"'') cfg.config); - }; + xdg.configFile = mkMerge ([{ + "bat/config" = mkIf (cfg.config != { }) { + text = concatStringsSep "\n" + (mapAttrsToList (n: v: ''--${n}="${v}"'') cfg.config); + }; + }] ++ flip mapAttrsToList cfg.themes + (name: body: { "bat/themes/${name}.tmTheme" = { text = body; }; })); }; }