From fc2a8842ea5106640eb89ec522dde9120df82d8a Mon Sep 17 00:00:00 2001 From: Li Yang <71299093+liyangau@users.noreply.github.com> Date: Thu, 2 Nov 2023 04:40:14 +1100 Subject: [PATCH] k9s: add hotkey option (#4617) * k9s: add hotkey option This PR adds an option to customise k9s hotkeys. The keyword `hotKey` must be in camel case on the user config. * Update modules/programs/k9s.nix Co-authored-by: Paul Meyer <49727155+katexochen@users.noreply.github.com> * fix formatting --------- Co-authored-by: Paul Meyer <49727155+katexochen@users.noreply.github.com> --- modules/programs/k9s.nix | 29 ++++++++++++++++++- .../programs/k9s/example-hotkey-expected.yml | 5 ++++ .../modules/programs/k9s/example-settings.nix | 14 ++++++++- 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 tests/modules/programs/k9s/example-hotkey-expected.yml diff --git a/modules/programs/k9s.nix b/modules/programs/k9s.nix index b32769cc0..78dbe71ca 100644 --- a/modules/programs/k9s.nix +++ b/modules/programs/k9s.nix @@ -8,7 +8,7 @@ let yamlFormat = pkgs.formats.yaml { }; in { - meta.maintainers = [ hm.maintainers.katexochen ]; + meta.maintainers = with maintainers; [ katexochen liyangau ]; options.programs.k9s = { enable = @@ -49,6 +49,29 @@ in { }; ''; }; + + hotkey = mkOption { + type = yamlFormat.type; + default = { }; + description = '' + hotkeys written to + {file}`$XDG_CONFIG_HOME/k9s/hotkey.yml`. See + + for supported values. + ''; + example = literalExpression '' + hotkey = { + # Make sure this is camel case + hotKey = { + shift-0 = { + shortCut = "Shift-0"; + description = "Viewing pods"; + command = "pods"; + }; + }; + }; + ''; + }; }; config = mkIf cfg.enable { @@ -61,5 +84,9 @@ in { xdg.configFile."k9s/skin.yml" = mkIf (cfg.skin != { }) { source = yamlFormat.generate "k9s-skin" cfg.skin; }; + + xdg.configFile."k9s/hotkey.yml" = mkIf (cfg.hotkey != { }) { + source = yamlFormat.generate "k9s-hotkey" cfg.hotkey; + }; }; } diff --git a/tests/modules/programs/k9s/example-hotkey-expected.yml b/tests/modules/programs/k9s/example-hotkey-expected.yml new file mode 100644 index 000000000..cae3005dc --- /dev/null +++ b/tests/modules/programs/k9s/example-hotkey-expected.yml @@ -0,0 +1,5 @@ +hotKey: + shift-0: + command: pods + description: Viewing pods + shortCut: Shift-0 diff --git a/tests/modules/programs/k9s/example-settings.nix b/tests/modules/programs/k9s/example-settings.nix index ffe521448..0100aa93c 100644 --- a/tests/modules/programs/k9s/example-settings.nix +++ b/tests/modules/programs/k9s/example-settings.nix @@ -13,7 +13,15 @@ headless = false; }; }; - + hotkey = { + hotKey = { + shift-0 = { + shortCut = "Shift-0"; + description = "Viewing pods"; + command = "pods"; + }; + }; + }; skin = { k9s = { body = { @@ -35,8 +43,12 @@ home-files/.config/k9s/config.yml \ ${./example-config-expected.yml} assertFileExists home-files/.config/k9s/skin.yml + assertFileExists home-files/.config/k9s/hotkey.yml assertFileContent \ home-files/.config/k9s/skin.yml \ ${./example-skin-expected.yml} + assertFileContent \ + home-files/.config/k9s/hotkey.yml \ + ${./example-hotkey-expected.yml} ''; }