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

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

      set -efu

      dtach=
      profile=default
      singleton=
      while :; do
        case ''${1-} in
          --dtach)
            dtach=1
            shift
            ;;
          --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 "$dtach" = 1; then
        if test $# = 0; then
          _CURRENT_DESKTOP_NAME=''${_CURRENT_DESKTOP_NAME-$(${pkgs.xextras}/bin/net-current-desktop)}
          SHELL=''${SHELL-${pkgs.bash}/bin/bash}
          sock=$XDG_RUNTIME_DIR/Alacritty-$DISPLAY-dtach-$_CURRENT_DESKTOP_NAME-$$.sock
          set -- -e ${pkgs.dtach}/bin/dtach -c "$sock" -r winch -z "$SHELL"
        else
          echo 'alacritty-tv: warning: option --dtach ignored: arguments provided' >&2
        fi
      fi

      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
  ];
}