aboutsummaryrefslogtreecommitdiff
path: root/home-manager/tests/modules/programs/fish/functions.nix
blob: 424d0a288c7f60f8ccf2954b7d24ec2b53b3a2f1 (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
{ config, lib, pkgs, ... }:

with lib;

let

  func = pkgs.writeText "func.fish" ''
    function func
      echo "Hello"
    end
  '';

  funcEvent = pkgs.writeText "func-event.fish" ''
    function func-event --on-event="fish_command_not_found"
      echo "Not found!"
    end
  '';

in {
  config = {
    programs.fish = {
      enable = true;

      functions = {
        func = ''echo "Hello"'';
        func-event = {
          body = ''echo "Not found!"'';
          onEvent = "fish_command_not_found";
        };
      };
    };

    nmt = {
      description =
        "if fish.function is set, check file exists and contents match";
      script = ''
        assertFileExists home-files/.config/fish/functions/func.fish
        echo ${func}
        assertFileContent home-files/.config/fish/functions/func.fish ${func}

        assertFileExists home-files/.config/fish/functions/func-event.fish
        echo ${funcEvent}
        assertFileContent home-files/.config/fish/functions/func-event.fish ${funcEvent}
      '';

    };
  };
}