From 43845d04f83d44d744206ea9884b8206e7640633 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Wed, 11 Sep 2024 20:25:31 -0400 Subject: [PATCH] git: add diff-highlight diff pager option This adds a new diff-highlight option to make use of the simple included git diff highlighter that comes with canonical git. For more info, see https://github.com/git/git/blob/master/contrib/diff-highlight/README --- modules/programs/git.nix | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/modules/programs/git.nix b/modules/programs/git.nix index 3f5cdc7cc..07d01ab9d 100644 --- a/modules/programs/git.nix +++ b/modules/programs/git.nix @@ -214,6 +214,24 @@ in { }; }; + diff-highlight = { + enable = mkEnableOption "" // { + description = '' + Enable the contrib {command}`diff-highlight` syntax highlighter. + See , + ''; + }; + + pagerOpts = mkOption { + type = types.listOf types.str; + default = [ ]; + example = [ "--tabs=4" "-RFX" ]; + description = '' + Arguments to be passed to {command}`less`. + ''; + }; + }; + difftastic = { enable = mkEnableOption "" // { description = '' @@ -360,11 +378,15 @@ in { home.packages = [ cfg.package ]; assertions = [{ assertion = let - enabled = - [ cfg.delta.enable cfg.diff-so-fancy.enable cfg.difftastic.enable ]; + enabled = [ + cfg.delta.enable + cfg.diff-so-fancy.enable + cfg.difftastic.enable + cfg.diff-highlight.enable + ]; in count id enabled <= 1; message = - "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."; + "Only one of 'programs.git.delta.enable' or 'programs.git.difftastic.enable' or 'programs.git.diff-so-fancy.enable' or 'programs.git.diff-highlight' can be set to true at the same time."; }]; programs.git.iniContent.user = { @@ -479,6 +501,18 @@ in { }; }) + (mkIf cfg.diff-highlight.enable { + programs.git.iniContent = let + dhCommand = + "${cfg.package}/share/git/contrib/diff-highlight/diff-highlight"; + in { + core.pager = "${dhCommand} | ${getExe pkgs.less} ${ + escapeShellArgs cfg.diff-highlight.pagerOpts + }"; + interactive.diffFilter = dhCommand; + }; + }) + (mkIf cfg.difftastic.enable { home.packages = [ cfg.difftastic.package ];