From 2874c6fce6de69eaedaa690b5fd6d3c70a2827af Mon Sep 17 00:00:00 2001 From: ilaumjd Date: Sun, 1 Oct 2023 21:41:55 +0700 Subject: [PATCH] thefuck: add module --- modules/misc/news.nix | 7 ++++ modules/modules.nix | 1 + modules/programs/thefuck.nix | 41 +++++++++++++++++++ tests/default.nix | 1 + tests/modules/programs/thefuck/default.nix | 4 ++ .../programs/thefuck/integration-disabled.nix | 18 ++++++++ .../programs/thefuck/integration-enabled.nix | 23 +++++++++++ 7 files changed, 95 insertions(+) create mode 100644 modules/programs/thefuck.nix create mode 100644 tests/modules/programs/thefuck/default.nix create mode 100644 tests/modules/programs/thefuck/integration-disabled.nix create mode 100644 tests/modules/programs/thefuck/integration-enabled.nix diff --git a/modules/misc/news.nix b/modules/misc/news.nix index f52969df..d402df93 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1266,6 +1266,13 @@ in A new module is available: 'programs.zsh.zsh-abbr' ''; } + + { + time = "2023-10-04T06:44:15+00:00"; + message = '' + A new module is available: 'programs.thefuck'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index cb42ea7e..c5e952bc 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -204,6 +204,7 @@ let ./programs/terminator.nix ./programs/termite.nix ./programs/texlive.nix + ./programs/thefuck.nix ./programs/thunderbird.nix ./programs/timidity.nix ./programs/tint2.nix diff --git a/modules/programs/thefuck.nix b/modules/programs/thefuck.nix new file mode 100644 index 00000000..1827d972 --- /dev/null +++ b/modules/programs/thefuck.nix @@ -0,0 +1,41 @@ +{ config, lib, pkgs, ... }: +with lib; +let cfg = config.programs.thefuck; +in { + meta.maintainers = [ hm.maintainers.ilaumjd ]; + + options.programs.thefuck = { + enable = mkEnableOption + "thefuck - magnificent app that corrects your previous console command"; + + package = mkPackageOption pkgs "thefuck" { }; + + enableBashIntegration = mkOption { + default = true; + type = types.bool; + description = '' + Whether to enable Bash integration. + ''; + }; + + enableZshIntegration = mkOption { + default = true; + type = types.bool; + description = '' + Whether to enable Zsh integration. + ''; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ cfg.package ]; + + programs.bash.initExtra = mkIf cfg.enableBashIntegration '' + eval "$(${cfg.package}/bin/thefuck --alias)" + ''; + + programs.zsh.initExtra = mkIf cfg.enableZshIntegration '' + eval "$(${cfg.package}/bin/thefuck --alias)" + ''; + }; +} diff --git a/tests/default.nix b/tests/default.nix index 7ae8e6dc..182c7e27 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -139,6 +139,7 @@ import nmt { ./modules/programs/starship ./modules/programs/taskwarrior ./modules/programs/texlive + ./modules/programs/thefuck ./modules/programs/tmate ./modules/programs/tmux ./modules/programs/topgrade diff --git a/tests/modules/programs/thefuck/default.nix b/tests/modules/programs/thefuck/default.nix new file mode 100644 index 00000000..533eabf8 --- /dev/null +++ b/tests/modules/programs/thefuck/default.nix @@ -0,0 +1,4 @@ +{ + thefuck-integration-enabled = ./integration-enabled.nix; + thefuck-integration-disabled = ./integration-disabled.nix; +} diff --git a/tests/modules/programs/thefuck/integration-disabled.nix b/tests/modules/programs/thefuck/integration-disabled.nix new file mode 100644 index 00000000..0afeb8d8 --- /dev/null +++ b/tests/modules/programs/thefuck/integration-disabled.nix @@ -0,0 +1,18 @@ +{ ... }: + +{ + programs = { + thefuck.enable = true; + thefuck.enableBashIntegration = false; + thefuck.enableZshIntegration = false; + bash.enable = true; + zsh.enable = true; + }; + + test.stubs.thefuck = { }; + + nmt.script = '' + assertFileNotRegex home-files/.bashrc '@thefuck@/bin/thefuck' + assertFileNotRegex home-files/.zshrc '@thefuck@/bin/thefuck' + ''; +} diff --git a/tests/modules/programs/thefuck/integration-enabled.nix b/tests/modules/programs/thefuck/integration-enabled.nix new file mode 100644 index 00000000..eb8e7f2a --- /dev/null +++ b/tests/modules/programs/thefuck/integration-enabled.nix @@ -0,0 +1,23 @@ +{ ... }: + +{ + programs = { + thefuck.enable = true; + bash.enable = true; + zsh.enable = true; + }; + + test.stubs.thefuck = { }; + + nmt.script = '' + assertFileExists home-files/.bashrc + assertFileContains \ + home-files/.bashrc \ + 'eval "$(@thefuck@/bin/thefuck --alias)"' + + assertFileExists home-files/.zshrc + assertFileContains \ + home-files/.zshrc \ + 'eval "$(@thefuck@/bin/thefuck --alias)"' + ''; +}