From db9a98e178b57a8aff46b3482dfccb3f4d8d4ce3 Mon Sep 17 00:00:00 2001 From: Nicholas Ciechanowski Date: Mon, 16 Dec 2024 10:17:54 +0000 Subject: [PATCH] pay-respects: add module Add pay-respects module including shell integration support for bash, zsh, fish and nushell. --- modules/lib/maintainers.nix | 6 ++ modules/misc/news.nix | 10 +++ modules/modules.nix | 1 + modules/programs/pay-respects.nix | 61 +++++++++++++++++++ tests/default.nix | 1 + .../modules/programs/pay-respects/default.nix | 4 ++ .../pay-respects/integration-disabled.nix | 22 +++++++ .../pay-respects/integration-enabled.nix | 33 ++++++++++ 8 files changed, 138 insertions(+) create mode 100644 modules/programs/pay-respects.nix create mode 100644 tests/modules/programs/pay-respects/default.nix create mode 100644 tests/modules/programs/pay-respects/integration-disabled.nix create mode 100644 tests/modules/programs/pay-respects/integration-enabled.nix diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix index 91ecb47be..64afe7615 100644 --- a/modules/lib/maintainers.nix +++ b/modules/lib/maintainers.nix @@ -628,4 +628,10 @@ keys = [{ fingerprint = "BC82 4BB5 1656 D144 285E A0EC D382 C4AF EECE AA90"; }]; }; + ALameLlama = { + name = "Nicholas Ciechanowski"; + email = "NicholasACiechanowski@gmail.com"; + github = "ALameLlama"; + githubId = 55490546; + }; } diff --git a/modules/misc/news.nix b/modules/misc/news.nix index a0150bf32..f2f62dd82 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1899,6 +1899,16 @@ in { registry with the option 'programs.nushell.plugins'. ''; } + + { + time = "2024-12-21T17:07:49+00:00"; + message = '' + A new module is available: 'programs.pay-respects'. + + Pay Respects is a shell command suggestions tool and command-not-found + and thefuck replacement written in Rust. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 5d40a82fc..ba85135de 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -191,6 +191,7 @@ let ./programs/pandoc.nix ./programs/papis.nix ./programs/password-store.nix + ./programs/pay-respects.nix ./programs/pazi.nix ./programs/pet.nix ./programs/pidgin.nix diff --git a/modules/programs/pay-respects.nix b/modules/programs/pay-respects.nix new file mode 100644 index 000000000..ea47bee4c --- /dev/null +++ b/modules/programs/pay-respects.nix @@ -0,0 +1,61 @@ +{ config, lib, pkgs, ... }: +let + inherit (lib) mkEnableOption mkPackageOption getExe optionalString mkIf; + + cfg = config.programs.pay-respects; + payRespectsCmd = getExe cfg.package; +in { + meta.maintainers = [ lib.hm.maintainers.ALameLlama ]; + + options.programs.pay-respects = { + enable = mkEnableOption "pay-respects"; + + package = mkPackageOption pkgs "pay-respects" { }; + + enableBashIntegration = mkEnableOption "Bash integration" // { + default = true; + }; + + enableZshIntegration = mkEnableOption "Zsh integration" // { + default = true; + }; + + enableFishIntegration = mkEnableOption "Fish integration" // { + default = true; + }; + + enableNushellIntegration = mkEnableOption "Nushell integration" // { + default = true; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ cfg.package ]; + + programs = { + bash.initExtra = '' + ${optionalString cfg.enableBashIntegration '' + eval "$(${payRespectsCmd} bash --alias)" + ''} + ''; + + zsh.initExtra = '' + ${optionalString cfg.enableZshIntegration '' + eval "$(${payRespectsCmd} zsh --alias)" + ''} + ''; + + fish.interactiveShellInit = '' + ${optionalString cfg.enableFishIntegration '' + ${payRespectsCmd} fish --alias | source + ''} + ''; + + nushell.extraConfig = '' + ${optionalString cfg.enableNushellIntegration '' + ${payRespectsCmd} nushell --alias [] + ''} + ''; + }; + }; +} diff --git a/tests/default.nix b/tests/default.nix index 710b06668..1acdc43dd 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -126,6 +126,7 @@ in import nmtSrc { ./modules/programs/openstackclient ./modules/programs/pandoc ./modules/programs/papis + ./modules/programs/pay-respects ./modules/programs/pet ./modules/programs/pistol ./modules/programs/pls diff --git a/tests/modules/programs/pay-respects/default.nix b/tests/modules/programs/pay-respects/default.nix new file mode 100644 index 000000000..44334d3ac --- /dev/null +++ b/tests/modules/programs/pay-respects/default.nix @@ -0,0 +1,4 @@ +{ + pay-respects-integration-enabled = ./integration-enabled.nix; + pay-respects-integration-disabled = ./integration-disabled.nix; +} diff --git a/tests/modules/programs/pay-respects/integration-disabled.nix b/tests/modules/programs/pay-respects/integration-disabled.nix new file mode 100644 index 000000000..fa0806d3d --- /dev/null +++ b/tests/modules/programs/pay-respects/integration-disabled.nix @@ -0,0 +1,22 @@ +{ ... }: { + programs = { + pay-respects.enable = true; + pay-respects.enableBashIntegration = false; + pay-respects.enableFishIntegration = false; + pay-respects.enableZshIntegration = false; + pay-respects.enableNushellIntegration = false; + bash.enable = true; + zsh.enable = true; + fish.enable = true; + nushell.enable = true; + }; + + test.stubs.pay-respects = { }; + + nmt.script = '' + assertFileNotRegex home-files/.bashrc '@pay-respects@/bin/dummy' + assertFileNotRegex home-files/.zshrc '@pay-respects@/bin/dummy' + assertFileNotRegex home-files/.config/fish/config.fish '@pay-respects@/bin/dummy' + assertFileNotRegex home-files/.config/nushell/config.nu '@pay-respects@/bin/dummy' + ''; +} diff --git a/tests/modules/programs/pay-respects/integration-enabled.nix b/tests/modules/programs/pay-respects/integration-enabled.nix new file mode 100644 index 000000000..d5b3d980c --- /dev/null +++ b/tests/modules/programs/pay-respects/integration-enabled.nix @@ -0,0 +1,33 @@ +{ ... }: { + programs = { + pay-respects.enable = true; + bash.enable = true; + zsh.enable = true; + fish.enable = true; + nushell.enable = true; + }; + + test.stubs.pay-respects = { }; + + nmt.script = '' + assertFileExists home-files/.bashrc + assertFileContains \ + home-files/.bashrc \ + 'eval "$(@pay-respects@/bin/dummy bash --alias)"' + + assertFileExists home-files/.zshrc + assertFileContains \ + home-files/.zshrc \ + 'eval "$(@pay-respects@/bin/dummy zsh --alias)"' + + assertFileExists home-files/.config/fish/config.fish + assertFileContains \ + home-files/.config/fish/config.fish \ + '@pay-respects@/bin/dummy fish --alias | source' + + assertFileExists home-files/.config/nushell/config.nu + assertFileContains \ + home-files/.config/nushell/config.nu \ + '@pay-respects@/bin/dummy nushell --alias []' + ''; +}