thefuck: add instant mode option

Also do a slight code cleanup.
This commit is contained in:
Gabe Dunn 2023-10-12 14:25:31 -07:00 committed by Robert Helgesson
parent b3acf1dc78
commit 3e1f8df4f0
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
4 changed files with 48 additions and 11 deletions

View file

@ -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;
};
}

View file

@ -1,4 +1,5 @@
{
thefuck-integration-enabled = ./integration-enabled.nix;
thefuck-integration-enabled-instant = ./integration-enabled-instant.nix;
thefuck-integration-disabled = ./integration-disabled.nix;
}

View file

@ -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'"'"')"'
'';
}

View file

@ -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'"'"')"'
'';
}