git: add basic support for delta

PR #1198
This commit is contained in:
Mario Rodas 2020-04-26 04:20:00 -05:00 committed by Robert Helgesson
parent 03b4f81679
commit cba7b6ee6e
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
4 changed files with 51 additions and 0 deletions

View file

@ -1503,6 +1503,16 @@ in
A new module is available: 'programs.aria2' A new module is available: 'programs.aria2'
''; '';
} }
{
time = "2020-05-04T21:19:43+00:00";
condition = config.programs.git.enable;
message = ''
The Git module now supports the 'delta' syntax highlighter.
It can be enabled through the option 'programs.git.delta.enable'.
'';
}
]; ];
}; };
} }

View file

@ -215,6 +215,24 @@ in {
''; '';
}; };
}; };
delta = {
enable = mkEnableOption "" // {
description = ''
Whether to enable the <command>delta</command> syntax highlighter.
See <link xlink:href="https://github.com/dandavison/delta" />.
'';
};
options = mkOption {
type = types.listOf types.str;
default = [ ];
example = [ "--dark" ];
description = ''
Extra command line options given to delta.
'';
};
};
}; };
}; };
@ -309,5 +327,16 @@ in {
([ "git-lfs" "smudge" ] ++ skipArg ++ [ "--" "%f" ]); ([ "git-lfs" "smudge" ] ++ skipArg ++ [ "--" "%f" ]);
}; };
}) })
(mkIf cfg.delta.enable {
programs.git.iniContent = let
deltaArgs = [ "${pkgs.gitAndTools.delta}/bin/delta" ]
++ cfg.delta.options;
in {
core.pager = concatStringsSep " " deltaArgs;
interactive.diffFilter =
concatStringsSep " " (deltaArgs ++ [ "--color-only" ]);
};
})
]); ]);
} }

View file

@ -6,6 +6,9 @@
[commit] [commit]
gpgSign = true gpgSign = true
[core]
pager = "@deltaCommand@ --dark"
[extra] [extra]
boolean = true boolean = true
integer = 38 integer = 38
@ -28,6 +31,9 @@
[gpg] [gpg]
program = "path-to-gpg" program = "path-to-gpg"
[interactive]
diffFilter = "@deltaCommand@ --dark --color-only"
[user] [user]
email = "user@example.org" email = "user@example.org"
name = "John Doe" name = "John Doe"

View file

@ -15,6 +15,8 @@ let
pkgs.substituteAll { pkgs.substituteAll {
src = path; src = path;
deltaCommand = "${pkgs.gitAndTools.delta}/bin/delta";
git_include_path = pkgs.writeText "contents" git_include_path = pkgs.writeText "contents"
(builtins.readFile ./git-expected-include.conf); (builtins.readFile ./git-expected-include.conf);
}; };
@ -56,6 +58,10 @@ in {
userEmail = "user@example.org"; userEmail = "user@example.org";
userName = "John Doe"; userName = "John Doe";
lfs.enable = true; lfs.enable = true;
delta = {
enable = true;
options = [ "--dark" ];
};
} }
{ {