From 088f23f690126d9d6d96569dfb6369560268a53c Mon Sep 17 00:00:00 2001 From: stuebinm Date: Tue, 12 Sep 2023 16:49:49 +0200 Subject: [PATCH] bat: allow adding custom syntaxes Adds an option to add custom syntax files to bat's cache, analogous to the existing programs.bat.themes option. --- modules/programs/bat.nix | 23 ++++++++++++++++++++++- tests/modules/programs/bat/bat.nix | 11 +++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/modules/programs/bat.nix b/modules/programs/bat.nix index ccef131e5..a4197cc21 100644 --- a/modules/programs/bat.nix +++ b/modules/programs/bat.nix @@ -60,6 +60,24 @@ in { ''; }; + syntaxes = mkOption { + type = types.attrsOf types.lines; + default = { }; + example = literalExpression '' + { + syntaxes.gleam = builtins.readFile (pkgs.fetchFromGitHub { + owner = "molnarmark"; + repo = "sublime-gleam"; + rev = "2e761cdb1a87539d827987f997a20a35efd68aa9"; + hash = "sha256-Zj2DKTcO1t9g18qsNKtpHKElbRSc9nBRE2QBzRn9+qs="; + } + "/syntax/gleam.sublime-syntax"); + } + ''; + description = '' + Additional syntaxes to provide. + ''; + }; + }; config = mkIf cfg.enable { @@ -69,7 +87,10 @@ in { "bat/config" = mkIf (cfg.config != { }) { text = toConfigFile cfg.config; }; }] ++ flip mapAttrsToList cfg.themes - (name: body: { "bat/themes/${name}.tmTheme" = { text = body; }; })); + (name: body: { "bat/themes/${name}.tmTheme" = { text = body; }; }) + ++ flip mapAttrsToList cfg.syntaxes (name: body: { + "bat/syntaxes/${name}.sublime-syntax" = { text = body; }; + })); home.activation.batCache = hm.dag.entryAfter [ "linkGeneration" ] '' ( diff --git a/tests/modules/programs/bat/bat.nix b/tests/modules/programs/bat/bat.nix index e98612922..88b2a40cd 100644 --- a/tests/modules/programs/bat/bat.nix +++ b/tests/modules/programs/bat/bat.nix @@ -16,6 +16,10 @@ with lib; themes.testtheme = '' This is a test theme. ''; + + syntaxes.testsyntax = '' + This is a test syntax. + ''; }; test.stubs.bat = { }; @@ -37,6 +41,13 @@ with lib; This is a test theme. '' } + + assertFileExists home-files/.config/bat/syntaxes/testsyntax.sublime-syntax + assertFileContent home-files/.config/bat/syntaxes/testsyntax.sublime-syntax ${ + pkgs.writeText "bat.expected" '' + This is a test syntax. + '' + } ''; }; }