From f23073f1daa769a28a12ac587eea487aa8afb196 Mon Sep 17 00:00:00 2001 From: Pamplemousse Date: Thu, 11 Nov 2021 11:32:48 +0100 Subject: [PATCH] less: allow customization Signed-off-by: Pamplemousse --- .github/CODEOWNERS | 3 ++ modules/lib/maintainers.nix | 7 ++++ modules/misc/news.nix | 7 ++++ modules/modules.nix | 1 + modules/programs/less.nix | 32 +++++++++++++++++++ tests/default.nix | 1 + tests/modules/programs/less/default.nix | 1 + .../programs/less/less-with-custom-keys.nix | 26 +++++++++++++++ 8 files changed, 78 insertions(+) create mode 100644 modules/programs/less.nix create mode 100644 tests/modules/programs/less/default.nix create mode 100644 tests/modules/programs/less/less-with-custom-keys.nix diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 316c36369..7e027b4cc 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -113,6 +113,9 @@ /modules/programs/lazygit.nix @kalhauge +/modules/programs/less.nix @pamplemousse +/tests/modules/programs/less @pamplemousse + /modules/programs/lesspipe.nix @rycee /modules/programs/lf.nix @owm111 diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix index dba4d5e30..0a88c6645 100644 --- a/modules/lib/maintainers.nix +++ b/modules/lib/maintainers.nix @@ -133,4 +133,11 @@ github = "hawkw"; githubId = 2796466; }; + + pamplemousse = { + name = "Xavier Maso"; + email = "xav.maso@gmail.com"; + github = "pamplemousse"; + githubId = 2647236; + }; } diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 186e9e489..533b0aee3 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -2252,6 +2252,13 @@ in '~/.taskrc'. ''; } + + { + time = "2021-11-30T22:28:12+00:00"; + message = '' + A new module is available: 'programs.less'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index cb8d2bdbb..b62d6f4aa 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -86,6 +86,7 @@ let ./programs/keychain.nix ./programs/kitty.nix ./programs/lazygit.nix + ./programs/less.nix ./programs/lesspipe.nix ./programs/lf.nix ./programs/lieer.nix diff --git a/modules/programs/less.nix b/modules/programs/less.nix new file mode 100644 index 000000000..3bee0a828 --- /dev/null +++ b/modules/programs/less.nix @@ -0,0 +1,32 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let cfg = config.programs.less; +in { + meta.maintainers = [ maintainers.pamplemousse ]; + + options = { + programs.less = { + enable = mkEnableOption "less, opposite of more"; + + keys = mkOption { + type = types.lines; + default = ""; + example = '' + s back-line + t forw-line + ''; + description = '' + Extra configuration for less written to + $HOME/.lesskey. + ''; + }; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ pkgs.less ]; + home.file.".lesskey".text = cfg.keys; + }; +} diff --git a/tests/default.nix b/tests/default.nix index 2b760dab7..6b21e355d 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -66,6 +66,7 @@ import nmt { ./modules/programs/irssi ./modules/programs/kakoune ./modules/programs/kitty + ./modules/programs/less ./modules/programs/lf ./modules/programs/lieer ./modules/programs/man diff --git a/tests/modules/programs/less/default.nix b/tests/modules/programs/less/default.nix new file mode 100644 index 000000000..f5fd77feb --- /dev/null +++ b/tests/modules/programs/less/default.nix @@ -0,0 +1 @@ +{ less-with-custom-keys = ./less-with-custom-keys.nix; } diff --git a/tests/modules/programs/less/less-with-custom-keys.nix b/tests/modules/programs/less/less-with-custom-keys.nix new file mode 100644 index 000000000..48f52b878 --- /dev/null +++ b/tests/modules/programs/less/less-with-custom-keys.nix @@ -0,0 +1,26 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + programs.less = { + enable = true; + + keys = '' + s back-line + t forw-line + ''; + }; + + test.stubs.less = { }; + + nmt.script = '' + assertFileExists home-files/.lesskey + assertFileContent home-files/.lesskey ${ + builtins.toFile "less.expected" '' + s back-line + t forw-line + '' + } + ''; +}