From 3e1f8df4f0036124e18a37ad227d3c97ba29d214 Mon Sep 17 00:00:00 2001 From: Gabe Dunn Date: Thu, 12 Oct 2023 14:25:31 -0700 Subject: [PATCH] thefuck: add instant mode option Also do a slight code cleanup. --- modules/programs/thefuck.nix | 28 +++++++++++++------ tests/modules/programs/thefuck/default.nix | 1 + .../thefuck/integration-enabled-instant.nix | 26 +++++++++++++++++ .../programs/thefuck/integration-enabled.nix | 4 +-- 4 files changed, 48 insertions(+), 11 deletions(-) create mode 100644 tests/modules/programs/thefuck/integration-enabled-instant.nix diff --git a/modules/programs/thefuck.nix b/modules/programs/thefuck.nix index 1827d972..36cd62d6 100644 --- a/modules/programs/thefuck.nix +++ b/modules/programs/thefuck.nix @@ -1,7 +1,8 @@ { config, lib, pkgs, ... }: + with lib; -let cfg = config.programs.thefuck; -in { + +{ meta.maintainers = [ hm.maintainers.ilaumjd ]; options.programs.thefuck = { @@ -10,6 +11,8 @@ in { package = mkPackageOption pkgs "thefuck" { }; + enableInstantMode = mkEnableOption "thefuck's experimental instant mode"; + enableBashIntegration = mkOption { default = true; type = types.bool; @@ -27,15 +30,22 @@ in { }; }; - config = mkIf cfg.enable { + config = let + cfg = config.programs.thefuck; + + cliArgs = cli.toGNUCommandLineShell { } { + alias = true; + enable-experimental-instant-mode = cfg.enableInstantMode; + }; + + shEvalCmd = '' + eval "$(${cfg.package}/bin/thefuck ${cliArgs})" + ''; + in mkIf cfg.enable { home.packages = [ cfg.package ]; - programs.bash.initExtra = mkIf cfg.enableBashIntegration '' - eval "$(${cfg.package}/bin/thefuck --alias)" - ''; + programs.bash.initExtra = mkIf cfg.enableBashIntegration shEvalCmd; - programs.zsh.initExtra = mkIf cfg.enableZshIntegration '' - eval "$(${cfg.package}/bin/thefuck --alias)" - ''; + programs.zsh.initExtra = mkIf cfg.enableZshIntegration shEvalCmd; }; } diff --git a/tests/modules/programs/thefuck/default.nix b/tests/modules/programs/thefuck/default.nix index 533eabf8..1250e0c0 100644 --- a/tests/modules/programs/thefuck/default.nix +++ b/tests/modules/programs/thefuck/default.nix @@ -1,4 +1,5 @@ { thefuck-integration-enabled = ./integration-enabled.nix; + thefuck-integration-enabled-instant = ./integration-enabled-instant.nix; thefuck-integration-disabled = ./integration-disabled.nix; } diff --git a/tests/modules/programs/thefuck/integration-enabled-instant.nix b/tests/modules/programs/thefuck/integration-enabled-instant.nix new file mode 100644 index 00000000..18584acb --- /dev/null +++ b/tests/modules/programs/thefuck/integration-enabled-instant.nix @@ -0,0 +1,26 @@ +{ ... }: + +{ + programs = { + thefuck = { + enable = true; + enableInstantMode = 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'"'"' '"'"'--enable-experimental-instant-mode'"'"')"' + + assertFileExists home-files/.zshrc + assertFileContains \ + home-files/.zshrc \ + 'eval "$(@thefuck@/bin/thefuck '"'"'--alias'"'"' '"'"'--enable-experimental-instant-mode'"'"')"' + ''; +} diff --git a/tests/modules/programs/thefuck/integration-enabled.nix b/tests/modules/programs/thefuck/integration-enabled.nix index eb8e7f2a..cb0d53eb 100644 --- a/tests/modules/programs/thefuck/integration-enabled.nix +++ b/tests/modules/programs/thefuck/integration-enabled.nix @@ -13,11 +13,11 @@ assertFileExists home-files/.bashrc assertFileContains \ home-files/.bashrc \ - 'eval "$(@thefuck@/bin/thefuck --alias)"' + 'eval "$(@thefuck@/bin/thefuck '"'"'--alias'"'"')"' assertFileExists home-files/.zshrc assertFileContains \ home-files/.zshrc \ - 'eval "$(@thefuck@/bin/thefuck --alias)"' + 'eval "$(@thefuck@/bin/thefuck '"'"'--alias'"'"')"' ''; }