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.
This commit is contained in:
stuebinm 2023-09-12 16:49:49 +02:00 committed by Robert Helgesson
parent d12c8fc85b
commit aed5ed979e
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
2 changed files with 33 additions and 1 deletions

View file

@ -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 { config = mkIf cfg.enable {
@ -69,7 +87,10 @@ in {
"bat/config" = "bat/config" =
mkIf (cfg.config != { }) { text = toConfigFile cfg.config; }; mkIf (cfg.config != { }) { text = toConfigFile cfg.config; };
}] ++ flip mapAttrsToList cfg.themes }] ++ 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" ] '' home.activation.batCache = hm.dag.entryAfter [ "linkGeneration" ] ''
( (

View file

@ -16,6 +16,10 @@ with lib;
themes.testtheme = '' themes.testtheme = ''
This is a test theme. This is a test theme.
''; '';
syntaxes.testsyntax = ''
This is a test syntax.
'';
}; };
test.stubs.bat = { }; test.stubs.bat = { };
@ -37,6 +41,13 @@ with lib;
This is a test theme. 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.
''
}
''; '';
}; };
} }