summaryrefslogtreecommitdiffstats
path: root/krebs/5pkgs/simple/pager.nix
blob: adc2cc67bd3c741b1bc1bad9b01d4a32f75a10d8 (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
{ pkgs }:

pkgs.symlinkJoin {
  name = "pager-wrapper";
  paths = [
    (pkgs.writeDashBin "pager" ''
      # usage: pager {view,shift,shiftview}
      #
      # Environment variables
      #
      #   PAGER_NAME (default: Pager)
      #     The environment variables specifies the application name under
      #     which resources are to be obtained.  PAGER_NAME should not contain
      #     “.” or “*” characters.
      #
      set -efu

      pidfile=$XDG_RUNTIME_DIR/pager.lock
      name=''${PAGER_NAME-Pager}

      if test -e "$pidfile" &&
         ${pkgs.procps}/bin/pgrep --pidfile="$pidfile" >/dev/null
      then
        ${pkgs.procps}/bin/pkill --pidfile="$pidfile"
        ${pkgs.coreutils}/bin/rm "$pidfile"
        exit
      fi

      echo $$ > "$pidfile"

      exec ${pkgs.xterm}/bin/xterm \
          -name "$name" \
          -ti vt340 \
          -xrm '*geometry: 32x10' \
          -xrm '*internalBorder: 2' \
          -e ${pkgs.haskellPackages.desktop-pager}/bin/pager "$@"
    '')
    pkgs.haskellPackages.pager
  ];
}