aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-09-26 16:56:36 +0100
committerAkshay <[email protected]>2021-09-26 16:56:36 +0100
commit5cdb4e421a809de51c3ebe8404e50d732721238b (patch)
tree73b71617c41b3e13edbf26035e821bb884d30441 /scripts
init
Diffstat (limited to 'scripts')
-rw-r--r--scripts/battery.nix60
-rw-r--r--scripts/default.nix26
-rw-r--r--scripts/record.nix33
-rw-r--r--scripts/up.nix24
-rw-r--r--scripts/webcam.nix5
5 files changed, 148 insertions, 0 deletions
diff --git a/scripts/battery.nix b/scripts/battery.nix
new file mode 100644
index 0000000..e75116b
--- /dev/null
+++ b/scripts/battery.nix
@@ -0,0 +1,60 @@
1
2{ pkgs, ...}:
3
4let
5 name = "bat";
6in
7 pkgs.writeScriptBin name
8 ''
9 red="\e[31m"
10 grn="\e[32m"
11 ylw="\e[33m"
12 cyn="\e[36m"
13 blu="\e[34m"
14 prp="\e[35m"
15 bprp="\e[35;1m"
16 rst="\e[0m"
17
18 bat_status=""
19 bat_status=$( cat /sys/class/power_supply/BAT0/capacity )
20 charging_status=$( cat /sys/class/power_supply/BAT0/status )
21
22 health() {
23 for i in {0..4}
24 do
25 if [[ $i -le $(( $bat_status/20 )) ]]; then
26 echo -ne "#[fg=colour1]· "
27 else
28 echo -ne "#[fg=colour8]· "
29 fi
30 done
31 echo
32 }
33
34 bat_status_small() {
35 if [[ "$charging_status" = *Charging* ]]; then
36 echo -ne "+$bat_status%"
37 else
38 echo -ne "$bat_status%"
39 fi
40 }
41
42 [ -z "$1" ] && {
43 bat_status_small
44 }
45
46 while getopts qi options
47 do
48 case $options in
49 i)
50 bat_status_small
51 ;;
52 q)
53 if [[ "$charging_status" = *Charging* ]]; then
54 echo -ne "+ $(health)"
55 else
56 health
57 fi
58 esac
59 done
60 ''
diff --git a/scripts/default.nix b/scripts/default.nix
new file mode 100644
index 0000000..84fcff3
--- /dev/null
+++ b/scripts/default.nix
@@ -0,0 +1,26 @@
1{ pkgs, ... }:
2
3let
4
5 # open a window with live video feed from the camera
6 webcam = pkgs.writeScriptBin "webcam" ''
7 ${pkgs.mpv}/bin/mpv av://v4l2:/dev/video0 --profile=low-latency --untimed
8 '';
9
10 # set git repo descriptions on cgit
11 git-set-desc = pkgs.writeScriptBin "git-set-desc" ''
12 remote=$(git remote get-url --push origin)
13 scp .git/description "$remote/description"
14 '';
15
16 # screen record with ffmpeg and slop
17 record = import ./record.nix pkgs;
18
19 # file uploader
20 uploader = import ./up.nix pkgs;
21
22 # battery script
23 battery = import ./battery.nix pkgs;
24
25in
26 [ webcam git-set-desc record uploader battery ]
diff --git a/scripts/record.nix b/scripts/record.nix
new file mode 100644
index 0000000..d5bfff5
--- /dev/null
+++ b/scripts/record.nix
@@ -0,0 +1,33 @@
1{ pkgs, ...}:
2
3let
4 name = "record";
5 slop = "${pkgs.slop}/bin/slop";
6 ffmpeg = "${pkgs.ffmpeg}/bin/ffmpeg";
7in
8 pkgs.writeScriptBin name
9 ''
10 echo starting recording ...
11 coords=$(${slop} -f "%x %y %w %h %g %i") || exit 1
12 read -r X Y W H G ID < <(echo $coords)
13 ${ffmpeg} \
14 -f x11grab \
15 -s "$W"x"$H" \
16 -i :0.0+$X,$Y \
17 -f alsa \
18 -thread_queue_size 512 \
19 -ac 2 \
20 -ar 48000 \
21 -i hw:0 \
22 -framerate 60 \
23 -vcodec libx264 \
24 -threads 4 \
25 -y \
26 /home/np/tmp/x.mkv
27
28 ${ffmpeg} \
29 -i /home/np/tmp/x.mkv \
30 -pix_fmt yuv420p \
31 -vf scale=-2:1080 \
32 "/home/np/vids/rec/$1"
33 ''
diff --git a/scripts/up.nix b/scripts/up.nix
new file mode 100644
index 0000000..c4f7c7a
--- /dev/null
+++ b/scripts/up.nix
@@ -0,0 +1,24 @@
1{ pkgs, ... }:
2let
3 name = "up";
4 xclip = "${pkgs.xclip}/bin/xclip";
5in
6pkgs.writeScriptBin name
7 ''
8 id=$( cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 3 | head -n 1 )
9
10 if [ $# != 1 ]; then
11 echo "needs an arg"
12 else
13 if [ -f "$1" ]; then
14 ext="''${1##*.}"
15 id="$id.$ext"
16 scp "$1" ferrn:~/www/nerd/uploads/"$id"
17 echo "https://u.peppe.rs/$id"
18 echo "https://u.peppe.rs/$id" | ${xclip} -selection clipboard
19 echo "https://u.peppe.rs/$id" | ${xclip} -i
20 else
21 echo "file does not exist"
22 fi
23 fi
24 ''
diff --git a/scripts/webcam.nix b/scripts/webcam.nix
new file mode 100644
index 0000000..0658dab
--- /dev/null
+++ b/scripts/webcam.nix
@@ -0,0 +1,5 @@
1#! /usr/bin/env bash
2
3mpv av://v4l2:/dev/video0 \
4 --profile=low-latency \
5 --untimed \