summaryrefslogtreecommitdiffstats
path: root/pkgs/simple/alacritty-tv.nix
blob: 86ca10f8fd401028ac49f0c9246e533ab8e8124f (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
{ 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
      singleton=
      while :; do
        case ''${1-} in
          --profile=*)
            profile=''${1#--profile=}
            shift
            ;;
          --singleton)
            singleton=1
            shift
            ;;
          *)
            break
        esac
      done

      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
      )

      if test "$singleton" = 1; then
        if ! ${pkgs.alacritty}/bin/alacritty --config-file "$config" msg create-window "$@"; then
          ${pkgs.alacritty}/bin/alacritty --config-file "$config" "$@" &
        fi
      else
        exec ${pkgs.alacritty}/bin/alacritty --config-file "$config" "$@"
      fi
    '')
    pkgs.alacritty
  ];
}