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:
parent
d12c8fc85b
commit
aed5ed979e
|
@ -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" ] ''
|
||||
(
|
||||
|
|
|
@ -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.
|
||||
''
|
||||
}
|
||||
'';
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue