summaryrefslogtreecommitdiffstats
path: root/pkgs/simple/alacritty-tv.nix
blob: 0d2fe59746057a9fa3885abb8c86b70cccbd6f6d (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
{ pkgs }:

pkgs.symlinkJoin {
  name = "alacritty-tv";
  paths = [
    (pkgs.writeDashBin "alacritty" ''
      # usage:
      #   alacritty [--profile=PROFILE] [--singleton] [ARGS...]
      # where
      #   PROFILE must have a corresponding file /etc/alacritty/PROFILE.toml

      set -efu

      profile=default
      case ''${1-} in
        --profile=*)
          profile=''${1#--profile=}
          shift
      esac

      config=/etc/alacritty/$profile.toml

      if ! test -e "$config"; then
        echo "$0: warning: bad profile: $profile; using default instead" >&2
        profile=default
        config=/etc/alacritty/default.toml
      fi

      export WINIT_X11_SCALE_FACTOR=$(
        ${pkgs.haskellPackages.xoutinfo}/bin/xoutinfo |
        ${pkgs.jq}/bin/jq .device_scale_factor
      )

      case ''${1-} in
        --singleton)
          shift
          if ! ${pkgs.alacritty}/bin/alacritty --config-file "$config" msg create-window "$@"; then
            ${pkgs.alacritty}/bin/alacritty --config-file "$config" "$@" &
          fi
          ;;
        *)
          exec ${pkgs.alacritty}/bin/alacritty --config-file "$config" "$@"
          ;;
      esac
    '')
    pkgs.alacritty
  ];
}