From 07b0b43a9235f30be3c80b34768d2067243f429f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Na=C3=AFm=20Favier?= Date: Wed, 8 Mar 2023 15:01:04 +0100 Subject: [PATCH] [backport 22.11] modules/git: make options passed to `less(1)` for `diff-so-fancy` configurable (#3751) The `-X` prevents that screen is cleared when showing a diff that's larger than my screen. I.e. when running `git diff` and press `q`, the last thing I want to see is the prompt with `git diff` and *not* the part of the diff I browsed, to be clear $ git diff $ Considering that this is somewhat opinionated, I decided to build an option which allows you to pass arbitrary commands to the less invocation. (cherry picked from commit cccd7622bdd23def01fd73a4e7bfa24de31238e7) Co-authored-by: Maximilian Bosch --- modules/programs/git.nix | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/programs/git.nix b/modules/programs/git.nix index 7dc1721f..f22bbb3b 100644 --- a/modules/programs/git.nix +++ b/modules/programs/git.nix @@ -340,6 +340,14 @@ in { ''; }; + pagerOpts = mkOption { + type = types.listOf types.str; + default = [ "--tabs=4" "-RFX" ]; + description = '' + Arguments to be passed to less. + ''; + }; + markEmptyLines = mkOption { type = types.bool; default = true; @@ -550,7 +558,9 @@ in { programs.git.iniContent = let dsfCommand = "${pkgs.diff-so-fancy}/bin/diff-so-fancy"; in { - core.pager = "${dsfCommand} | ${pkgs.less}/bin/less --tabs=4 -RFX"; + core.pager = "${dsfCommand} | ${pkgs.less}/bin/less ${ + escapeShellArgs cfg.diff-so-fancy.pagerOpts + }"; interactive.diffFilter = "${dsfCommand} --patch"; diff-so-fancy = { markEmptyLines = cfg.diff-so-fancy.markEmptyLines;