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

git: add option to use diff-so-fancy as diff tool

Add the option to use diff-so-fancy as diff tool in git. This makes
the shown diffs human readable instead of machine readable.
This commit is contained in:
Arjan Schrijver 2022-04-09 21:45:30 +02:00 committed by Robert Helgesson
parent d7b97de51a
commit 5872aad1d0
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89

View file

@ -296,6 +296,65 @@ in {
''; '';
}; };
}; };
diff-so-fancy = {
enable = mkEnableOption "" // {
description = ''
Enable the <command>diff-so-fancy</command> diff colorizer.
See <link xlink:href="https://github.com/so-fancy/diff-so-fancy" />.
'';
};
markEmptyLines = mkOption {
type = types.bool;
default = true;
example = false;
description = ''
Whether the first block of an empty line should be colored.
'';
};
changeHunkIndicators = mkOption {
type = types.bool;
default = true;
example = false;
description = ''
Simplify git header chunks to a more human readable format.
'';
};
stripLeadingSymbols = mkOption {
type = types.bool;
default = true;
example = false;
description = ''
Whether the <literal>+</literal> or <literal>-</literal> at
line-start should be removed.
'';
};
useUnicodeRuler = mkOption {
type = types.bool;
default = true;
example = false;
description = ''
By default, the separator for the file header uses Unicode
line-drawing characters. If this is causing output errors on
your terminal, set this to false to use ASCII characters instead.
'';
};
rulerWidth = mkOption {
type = types.nullOr types.int;
default = null;
example = false;
description = ''
By default, the separator for the file header spans the full
width of the terminal. Use this setting to set the width of
the file header manually.
'';
};
};
}; };
}; };
@ -303,9 +362,12 @@ in {
{ {
home.packages = [ cfg.package ]; home.packages = [ cfg.package ];
assertions = [{ assertions = [{
assertion = !(cfg.delta.enable && cfg.difftastic.enable); assertion = let
enabled =
[ cfg.delta.enable cfg.diff-so-fancy.enable cfg.difftastic.enable ];
in count id enabled <= 1;
message = message =
"Only one of 'programs.git.delta.enable' or 'programs.git.difftastic.enable' can be set to true at the same time."; "Only one of 'programs.git.delta.enable' or 'programs.git.difftastic.enable' or 'programs.git.diff-so-fancy.enable' can be set to true at the same time.";
}]; }];
programs.git.iniContent.user = { programs.git.iniContent.user = {
@ -432,5 +494,24 @@ in {
delta = cfg.delta.options; delta = cfg.delta.options;
}; };
}) })
(mkIf cfg.diff-so-fancy.enable {
home.packages = [ pkgs.diff-so-fancy ];
programs.git.iniContent =
let dsfCommand = "${pkgs.diff-so-fancy}/bin/diff-so-fancy";
in {
core.pager = "${dsfCommand} | ${pkgs.less}/bin/less --tabs=4 -RFX";
interactive.diffFilter = "${dsfCommand} --patch";
diff-so-fancy = {
markEmptyLines = cfg.diff-so-fancy.markEmptyLines;
changeHunkIndicators = cfg.diff-so-fancy.changeHunkIndicators;
stripLeadingSymbols = cfg.diff-so-fancy.stripLeadingSymbols;
useUnicodeRuler = cfg.diff-so-fancy.useUnicodeRuler;
rulerWidth = mkIf (cfg.diff-so-fancy.rulerWidth != null)
(cfg.diff-so-fancy.rulerWidth);
};
};
})
]); ]);
} }