summaryrefslogtreecommitdiff
path: root/alacritty/default.nix
blob: 15fc3a481aeb360e3b399e300d16c20631cd21bd (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
{

  config,
  zsh,

  pkgs ? (import ../pkgs.nix).edge {},

}: rec {

  defaultXDGOpenRules = [
    {
      name = "open-url";
      pattern = "(ipfs:|ipns:|magnet:|mailto:|gemini:|gopher:|https:|http:|news:|file:|git:|ssh:|ftp:)[^<>\"\\s{-}\\^⟨⟩`]+";
      xdgOpen = "$1";
    }
  ];

  xdgOpenRules = defaultXDGOpenRules ++ config.alacritty.xdgOpenRules;

  hints = {
    enabled = (builtins.map (r:
      {
        regex = r.pattern;
        hyperlinks = true;
        command = (pkgs.writeShellScript "alacritty-hints-${r.name}" ''
          xdg-open "${r.xdgOpen}"
        '');
        post_processing = true;
        mouse.enabled = true;
      }
    ) xdgOpenRules);
  };

  configFile = pkgs.writeText "alacritty-config" (
    builtins.replaceStrings
      ["$HINTS"]
      [(builtins.toJSON hints)]
      (builtins.readFile ./alacritty.yml)
    );

  alacritty = pkgs.writeScriptBin "alacritty" ''
    #!${pkgs.bash}/bin/bash

    exec ${pkgs.nixgl}/bin/nixGL ${pkgs.alacritty}/bin/alacritty \
      -o font.size=${builtins.toString config.alacritty.fontSize} \
      --config-file ${configFile} \
      -e "${zsh}/bin/zsh"
  '';
}