1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-12-27 20:29:47 +01:00

git: Add option to use difftastic as diff tool (#2850)

Difftastic is a syntax-aware diff tool which can be used with git.
This commit is contained in:
Roch D'Amour 2022-04-04 10:53:29 -04:00 committed by GitHub
parent cfab869fce
commit 0382c5f75e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -239,6 +239,34 @@ in {
};
};
difftastic = {
enable = mkEnableOption "" // {
description = ''
Enable the <command>difft</command> syntax highlighter.
See <link xlink:href="https://github.com/Wilfred/difftastic" />.
'';
};
background = mkOption {
type = types.enum [ "light" "dark" ];
default = "light";
example = "dark";
description = ''
Determines whether difftastic should use the lighter or darker colors
for syntax highlithing.
'';
};
color = mkOption {
type = types.enum [ "always" "auto" "never" ];
default = "auto";
example = "always";
description = ''
Determines when difftastic should color its output.
'';
};
};
delta = {
enable = mkEnableOption "" // {
description = ''
@ -274,6 +302,11 @@ in {
config = mkIf cfg.enable (mkMerge [
{
home.packages = [ cfg.package ];
assertions = [{
assertion = !(cfg.delta.enable && cfg.difftastic.enable);
message =
"Only one of 'programs.git.delta.enable' or 'programs.git.difftastic.enable' can be set to true at the same time.";
}];
programs.git.iniContent.user = {
name = mkIf (cfg.userName != null) cfg.userName;
@ -377,6 +410,18 @@ in {
};
})
(mkIf cfg.difftastic.enable {
home.packages = [ pkgs.difftastic ];
programs.git.iniContent = let
difftCommand =
"${pkgs.difftastic}/bin/difft --color ${cfg.difftastic.color} --background ${cfg.difftastic.background}";
in {
diff.external = difftCommand;
core.pager = "${pkgs.less}/bin/less -XF";
};
})
(mkIf cfg.delta.enable {
home.packages = [ pkgs.delta ];