summaryrefslogtreecommitdiff
path: root/users/seth/programs/fish.nix
blob: b1f792a7d26461f0e010dcc8a18b3627b48c6868 (plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
{
  config,
  lib,
  pkgs,
  ...
}:
let
  cfg = config.seth.programs.fish;
in
{
  options.seth.programs.fish = {
    enable = lib.mkEnableOption "Fish configuration";
    withPlugins = lib.mkEnableOption "Fish plugins" // {
      default = true;
    };
  };

  config = lib.mkIf cfg.enable (
    lib.mkMerge [
      {
        programs.fish = {
          enable = true;

          interactiveShellInit = ''
            ${lib.getExe pkgs.nix-your-shell} fish | source
          '';

          functions = {
            last_history_item.body = "echo $history[1]";
          };

          shellAbbrs = {
            nixgc = "sudo nix-collect-garbage -d && nix-collect-garbage -d";
            "!!" = {
              position = "anywhere";
              function = "last_history_item";
            };
          };
        };
      }

      # TODO: do i still need this weird sourcing?
      (lib.mkIf config.seth.standalone.enable {
        programs.fish = {
          interactiveShellInit = ''
            set -l nixfile ${config.home.homeDirectory}/.nix-profile/etc/profile.d/nix.fish
            if test -e $nixfile
            	source $nixfile
            end
          '';
        };
      })

      (lib.mkIf cfg.withPlugins {
        programs.fish = {
          plugins =
            let
              useFishPlugins = map (plugin: {
                name = plugin;
                inherit (pkgs.fishPlugins.${plugin}) src;
              });
            in
            useFishPlugins [ "autopair" ];
        };
      })
    ]
  );
}