mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-08 11:36:05 +01:00
diff-highlight: new module
Break out diff-highlight into its own module. Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
parent
2c8b962091
commit
7d03d5fb73
2 changed files with 98 additions and 33 deletions
97
modules/programs/diff-highlight.nix
Normal file
97
modules/programs/diff-highlight.nix
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
{
|
||||
config,
|
||||
options,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
cfg = config.programs.diff-highlight;
|
||||
|
||||
inherit (lib)
|
||||
mkEnableOption
|
||||
mkIf
|
||||
mkOption
|
||||
types
|
||||
;
|
||||
in
|
||||
{
|
||||
meta.maintainers = with lib.maintainers; [ khaneliman ];
|
||||
|
||||
imports = [
|
||||
(lib.mkRenamedOptionModule
|
||||
[ "programs" "git" "diff-highlight" "enable" ]
|
||||
[ "programs" "diff-highlight" "enable" ]
|
||||
)
|
||||
(lib.mkRenamedOptionModule
|
||||
[ "programs" "git" "diff-highlight" "pagerOpts" ]
|
||||
[ "programs" "diff-highlight" "pagerOpts" ]
|
||||
)
|
||||
];
|
||||
|
||||
options.programs.diff-highlight = {
|
||||
enable = mkEnableOption "" // {
|
||||
description = ''
|
||||
Enable the contrib {command}`diff-highlight` syntax highlighter.
|
||||
See <https://github.com/git/git/blob/master/contrib/diff-highlight/README>,
|
||||
'';
|
||||
};
|
||||
|
||||
pagerOpts = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
example = [
|
||||
"--tabs=4"
|
||||
"-RFX"
|
||||
];
|
||||
description = ''
|
||||
Arguments to be passed to {command}`less`.
|
||||
'';
|
||||
};
|
||||
|
||||
enableGitIntegration = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Whether to enable git integration for diff-highlight.
|
||||
|
||||
When enabled, diff-highlight will be configured as git's pager and diff filter.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config =
|
||||
let
|
||||
oldOption = lib.attrByPath [ "programs" "git" "diff-highlight" "enable" ] null options;
|
||||
oldOptionEnabled =
|
||||
oldOption != null && oldOption.isDefined && (builtins.length oldOption.files) > 0;
|
||||
in
|
||||
lib.mkMerge [
|
||||
(mkIf cfg.enable {
|
||||
# Auto-enable git integration if programs.git.diff-highlight.enable was set to true
|
||||
programs.diff-highlight.enableGitIntegration = lib.mkIf oldOptionEnabled (lib.mkOverride 1490 true);
|
||||
|
||||
warnings =
|
||||
lib.optional
|
||||
(
|
||||
cfg.enableGitIntegration && options.programs.diff-highlight.enableGitIntegration.highestPrio == 1490
|
||||
)
|
||||
"`programs.diff-highlight.enableGitIntegration` automatic enablement is deprecated. Please explicitly set `programs.diff-highlight.enableGitIntegration = true`.";
|
||||
})
|
||||
|
||||
(mkIf (cfg.enable && cfg.enableGitIntegration) {
|
||||
programs.git = {
|
||||
enable = lib.mkDefault true;
|
||||
iniContent =
|
||||
let
|
||||
gitPackage = config.programs.git.package;
|
||||
dhCommand = "${gitPackage}/share/git/contrib/diff-highlight/diff-highlight";
|
||||
in
|
||||
{
|
||||
core.pager = "${dhCommand} | ${lib.getExe pkgs.less} ${lib.escapeShellArgs cfg.pagerOpts}";
|
||||
interactive.diffFilter = dhCommand;
|
||||
};
|
||||
};
|
||||
})
|
||||
];
|
||||
}
|
||||
|
|
@ -292,27 +292,6 @@ in
|
|||
};
|
||||
};
|
||||
|
||||
diff-highlight = {
|
||||
enable = mkEnableOption "" // {
|
||||
description = ''
|
||||
Enable the contrib {command}`diff-highlight` syntax highlighter.
|
||||
See <https://github.com/git/git/blob/master/contrib/diff-highlight/README>,
|
||||
'';
|
||||
};
|
||||
|
||||
pagerOpts = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
example = [
|
||||
"--tabs=4"
|
||||
"-RFX"
|
||||
];
|
||||
description = ''
|
||||
Arguments to be passed to {command}`less`.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
difftastic = {
|
||||
enable = mkEnableOption "" // {
|
||||
description = ''
|
||||
|
|
@ -497,9 +476,9 @@ in
|
|||
let
|
||||
enabled = [
|
||||
(config.programs.delta.enable && config.programs.delta.enableGitIntegration)
|
||||
(config.programs.diff-highlight.enable && config.programs.diff-highlight.enableGitIntegration)
|
||||
cfg.diff-so-fancy.enable
|
||||
cfg.difftastic.enable
|
||||
cfg.diff-highlight.enable
|
||||
cfg.riff.enable
|
||||
cfg.patdiff.enable
|
||||
];
|
||||
|
|
@ -779,17 +758,6 @@ in
|
|||
};
|
||||
})
|
||||
|
||||
(mkIf cfg.diff-highlight.enable {
|
||||
programs.git.iniContent =
|
||||
let
|
||||
dhCommand = "${cfg.package}/share/git/contrib/diff-highlight/diff-highlight";
|
||||
in
|
||||
{
|
||||
core.pager = "${dhCommand} | ${lib.getExe pkgs.less} ${lib.escapeShellArgs cfg.diff-highlight.pagerOpts}";
|
||||
interactive.diffFilter = dhCommand;
|
||||
};
|
||||
})
|
||||
|
||||
(
|
||||
let
|
||||
difftCommand = "${lib.getExe cfg.difftastic.package} ${
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue