From 0382c5f75e9b4ffb0cdc75535c3e249019710a02 Mon Sep 17 00:00:00 2001 From: Roch D'Amour Date: Mon, 4 Apr 2022 10:53:29 -0400 Subject: [PATCH] git: Add option to use difftastic as diff tool (#2850) Difftastic is a syntax-aware diff tool which can be used with git. --- modules/programs/git.nix | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/modules/programs/git.nix b/modules/programs/git.nix index cf6ef3bcf..61792f866 100644 --- a/modules/programs/git.nix +++ b/modules/programs/git.nix @@ -239,6 +239,34 @@ in { }; }; + difftastic = { + enable = mkEnableOption "" // { + description = '' + Enable the difft syntax highlighter. + See . + ''; + }; + + 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 ];