2019-02-11 05:57:10 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.bat;
|
|
|
|
|
2023-04-18 14:57:55 +00:00
|
|
|
package = pkgs.bat;
|
|
|
|
|
2021-08-12 19:24:19 +00:00
|
|
|
toConfigFile = generators.toKeyValue {
|
|
|
|
mkKeyValue = k: v: "--${k}=${lib.escapeShellArg v}";
|
|
|
|
listsAsDuplicateKeys = true;
|
|
|
|
};
|
|
|
|
|
2020-02-01 23:39:17 +00:00
|
|
|
in {
|
2023-06-22 08:16:28 +00:00
|
|
|
meta.maintainers = [ ];
|
2019-02-11 05:57:10 +00:00
|
|
|
|
|
|
|
options.programs.bat = {
|
|
|
|
enable = mkEnableOption "bat, a cat clone with wings";
|
|
|
|
|
|
|
|
config = mkOption {
|
2021-08-12 19:24:19 +00:00
|
|
|
type = with types; attrsOf (either str (listOf str));
|
2020-02-01 23:39:17 +00:00
|
|
|
default = { };
|
2019-02-11 05:57:10 +00:00
|
|
|
example = {
|
|
|
|
theme = "TwoDark";
|
|
|
|
pager = "less -FR";
|
2021-08-12 19:24:19 +00:00
|
|
|
map-syntax = [ "*.jenkinsfile:Groovy" "*.props:Java Properties" ];
|
2019-02-11 05:57:10 +00:00
|
|
|
};
|
|
|
|
description = ''
|
|
|
|
Bat configuration.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-11-05 23:57:15 +00:00
|
|
|
extraPackages = mkOption {
|
|
|
|
type = types.listOf types.package;
|
|
|
|
default = [ ];
|
|
|
|
example = literalExpression
|
|
|
|
"with pkgs.bat-extras; [ batdiff batman batgrep batwatch ];";
|
|
|
|
description = ''
|
|
|
|
Additional bat packages to install.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-04-21 19:26:20 +00:00
|
|
|
themes = mkOption {
|
|
|
|
type = types.attrsOf types.lines;
|
|
|
|
default = { };
|
2021-10-09 09:14:08 +00:00
|
|
|
example = literalExpression ''
|
2020-04-21 19:26:20 +00:00
|
|
|
{
|
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-09-12 14:49:49 +00:00
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-02-11 05:57:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2023-04-18 14:57:55 +00:00
|
|
|
home.packages = [ package ] ++ cfg.extraPackages;
|
2019-02-11 05:57:10 +00:00
|
|
|
|
2020-04-21 19:26:20 +00:00
|
|
|
xdg.configFile = mkMerge ([{
|
2021-08-12 19:24:19 +00:00
|
|
|
"bat/config" =
|
|
|
|
mkIf (cfg.config != { }) { text = toConfigFile cfg.config; };
|
2020-04-21 19:26:20 +00:00
|
|
|
}] ++ flip mapAttrsToList cfg.themes
|
2023-09-12 14:49:49 +00:00
|
|
|
(name: body: { "bat/themes/${name}.tmTheme" = { text = body; }; })
|
|
|
|
++ flip mapAttrsToList cfg.syntaxes (name: body: {
|
|
|
|
"bat/syntaxes/${name}.sublime-syntax" = { text = body; };
|
|
|
|
}));
|
2023-04-18 14:57:55 +00:00
|
|
|
|
|
|
|
home.activation.batCache = hm.dag.entryAfter [ "linkGeneration" ] ''
|
2023-08-16 07:02:23 +00:00
|
|
|
(
|
|
|
|
export XDG_CACHE_HOME=${escapeShellArg config.xdg.cacheHome}
|
|
|
|
$VERBOSE_ECHO "Rebuilding bat theme cache"
|
|
|
|
$DRY_RUN_CMD ${lib.getExe package} cache --build
|
|
|
|
)
|
2023-04-18 14:57:55 +00:00
|
|
|
'';
|
2019-02-11 05:57:10 +00:00
|
|
|
};
|
|
|
|
}
|