aboutsummaryrefslogtreecommitdiff
path: root/scripts/default.nix
blob: 616be1c912432d75e935d988dd1b0dc476e74d0b (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
{ 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;

  # run-on-gpu script
  nvidia-offload = import ./nvidia-offload.nix pkgs;

  # fzf script to switch between tmux sessions
  tmux-fzf = pkgs.writeScriptBin "tmux-fzf" ''
    LIST_DATA="#{session_name}/#{window_name}/#{pane_current_command} @ #{pane_current_path}"
    FZF_COMMAND="${pkgs.fzf}/bin/fzf-tmux -p 80,30 --delimiter=: --with-nth 4"

    TARGET_SPEC="#{session_name}:#{window_id}:#{pane_id}:"

    LINE=$(tmux list-windows -a -F "$TARGET_SPEC $LIST_DATA" | $FZF_COMMAND) || exit 0
    args=(''${LINE//:/ })

    ${pkgs.tmux}/bin/tmux select-window -t ''${args[1]} && tmux switch-client -t ''${args[0]}
  '';

  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
  nvidia-offload
]