aboutsummaryrefslogtreecommitdiff
path: root/scripts/default.nix
blob: 72d0235e46ad742992bdd96dd803216e8a79f8f6 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
{ pkgs, ... }:

let

  # open a window with live video feed from the camera
  webcam = pkgs.writeScriptBin "webcam" ''
    ${pkgs.mpv}/bin/mpv av://v4l2:/dev/video0 --profile=low-latency --untimed
  '';

  # create new repo on fern
  git-new-repo = pkgs.writeScriptBin "git-new-repo" ''
    if [ $# -eq 0 ]; then
        echo "requires an arg"
        exit 1
    fi

    # $1 - section/repo-name

    ssh git@ferrn git init --bare "$1";
    git remote add origin git@ferrn:"$1";
    git push -u origin HEAD;
  '';

  # set git repo descriptions on cgit
  git-set-desc = pkgs.writeScriptBin "git-set-desc" ''
    remote=$(git remote get-url --push origin)
    scp .git/description "$remote/description"
  '';

  # screen record with ffmpeg and slop
  record = import ./record.nix pkgs;

  # file uploader
  uploader = import ./up.nix pkgs;

  # battery script
  battery = import ./battery.nix pkgs;

  # fzf script to switch between tmux sessions
  tmux-fzf = pkgs.writeScriptBin "tmux-fzf" ''
    tbin() {
      ${pkgs.tmux}/bin/tmux "$@"
    }
    fbin() {
      ${pkgs.fzf}/bin/fzf "$@"
    }

    __fzf() {
        fbin --cycle --height 7 --reverse
    }

    __list_to_fzf() {
        tbin ls -F "#{session_name}" | fzf
    }

    if [ -n "$TMUX" ]; then
        tbin switch-client -t "$(__list_to_fzf)"
    else
        tbin a -t "$(tbin ls -F "#{session_name}" | fbin)"
    fi
  '';

  touchscreen = "ELAN9008:00 04F3:2ED6";
  stylus = "ELAN9008:00 04F3:2ED6 Stylus Pen (0)";
  portait-transform = builtins.toString [ 0 (-1) 1 1 0 0 0 0 1 ];
  landscape-transform = builtins.toString [ 0 0 0 0 0 0 0 0 0 ];
  portrait = pkgs.writeScriptBin "portrait" ''
    ${pkgs.xorg.xrandr}/bin/xrandr -o left
    ${pkgs.xorg.xinput}/bin/xinput set-prop "${touchscreen}" --type=float "Coordinate Transformation Matrix" ${portait-transform}
    ${pkgs.xorg.xinput}/bin/xinput set-prop "${stylus}" --type=float "Coordinate Transformation Matrix" ${portait-transform}
  '';
  landscape = pkgs.writeScriptBin "landscape" ''
    ${pkgs.xorg.xrandr}/bin/xrandr -o normal
    ${pkgs.xorg.xinput}/bin/xinput set-prop "${touchscreen}" --type=float "Coordinate Transformation Matrix" ${landscape-transform}
    ${pkgs.xorg.xinput}/bin/xinput set-prop "${stylus}" --type=float "Coordinate Transformation Matrix" ${landscape-transform}
  '';

in
[
  webcam
  git-set-desc
  git-new-repo
  record
  uploader
  battery
  tmux-fzf
  portrait
  landscape
]