summary refs log tree commit diff
path: root/nixos/modules/programs/thefuck.nix
blob: e057d1ca657de21248a0baf2e2b2329f80285234 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{ config, pkgs, lib, ... }:

with lib;

let
  prg = config.programs;
  cfg = prg.thefuck;

  bashAndZshInitScript = ''
    eval $(${pkgs.thefuck}/bin/thefuck --alias ${cfg.alias})
  '';
  fishInitScript = ''
    ${pkgs.thefuck}/bin/thefuck --alias ${cfg.alias} | source
  '';
in
  {
    options = {
      programs.thefuck = {
        enable = mkEnableOption (lib.mdDoc "thefuck");

        alias = mkOption {
          default = "fuck";
          type = types.str;

          description = lib.mdDoc ''
            `thefuck` needs an alias to be configured.
            The default value is `fuck`, but you can use anything else as well.
          '';
        };
      };
    };

    config = mkIf cfg.enable {
      environment.systemPackages = with pkgs; [ thefuck ];

      programs.bash.interactiveShellInit = bashAndZshInitScript;
      programs.zsh.interactiveShellInit = mkIf prg.zsh.enable bashAndZshInitScript;
      programs.fish.interactiveShellInit = mkIf prg.fish.enable fishInitScript;
    };
  }