diff --git a/modules/programs/thefuck.nix b/modules/programs/thefuck.nix index 1827d9720..36cd62d62 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 533eabf8f..1250e0c06 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 000000000..18584acbd --- /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 eb8e7f2af..cb0d53eb5 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'"'"')"' ''; }