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

      set -efu

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

      config=/etc/alacritty/$profile.json

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

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