From 5cdb4e421a809de51c3ebe8404e50d732721238b Mon Sep 17 00:00:00 2001 From: Akshay Date: Sun, 26 Sep 2021 21:26:36 +0530 Subject: init --- scripts/battery.nix | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++ scripts/default.nix | 26 +++++++++++++++++++++++ scripts/record.nix | 33 +++++++++++++++++++++++++++++ scripts/up.nix | 24 +++++++++++++++++++++ scripts/webcam.nix | 5 +++++ 5 files changed, 148 insertions(+) create mode 100644 scripts/battery.nix create mode 100644 scripts/default.nix create mode 100644 scripts/record.nix create mode 100644 scripts/up.nix create mode 100644 scripts/webcam.nix (limited to 'scripts') 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 @@ + +{ pkgs, ...}: + +let + name = "bat"; +in + pkgs.writeScriptBin name + '' + red="\e[31m" + grn="\e[32m" + ylw="\e[33m" + cyn="\e[36m" + blu="\e[34m" + prp="\e[35m" + bprp="\e[35;1m" + rst="\e[0m" + + bat_status="" + bat_status=$( cat /sys/class/power_supply/BAT0/capacity ) + charging_status=$( cat /sys/class/power_supply/BAT0/status ) + + health() { + for i in {0..4} + do + if [[ $i -le $(( $bat_status/20 )) ]]; then + echo -ne "#[fg=colour1]· " + else + echo -ne "#[fg=colour8]· " + fi + done + echo + } + + bat_status_small() { + if [[ "$charging_status" = *Charging* ]]; then + echo -ne "+$bat_status%" + else + echo -ne "$bat_status%" + fi + } + + [ -z "$1" ] && { + bat_status_small + } + + while getopts qi options + do + case $options in + i) + bat_status_small + ;; + q) + if [[ "$charging_status" = *Charging* ]]; then + echo -ne "+ $(health)" + else + health + fi + esac + done + '' 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 @@ +{ 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 + ''; + + # 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; + +in + [ 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 @@ +{ pkgs, ...}: + +let + name = "record"; + slop = "${pkgs.slop}/bin/slop"; + ffmpeg = "${pkgs.ffmpeg}/bin/ffmpeg"; +in + pkgs.writeScriptBin name + '' + echo starting recording ... + coords=$(${slop} -f "%x %y %w %h %g %i") || exit 1 + read -r X Y W H G ID < <(echo $coords) + ${ffmpeg} \ + -f x11grab \ + -s "$W"x"$H" \ + -i :0.0+$X,$Y \ + -f alsa \ + -thread_queue_size 512 \ + -ac 2 \ + -ar 48000 \ + -i hw:0 \ + -framerate 60 \ + -vcodec libx264 \ + -threads 4 \ + -y \ + /home/np/tmp/x.mkv + + ${ffmpeg} \ + -i /home/np/tmp/x.mkv \ + -pix_fmt yuv420p \ + -vf scale=-2:1080 \ + "/home/np/vids/rec/$1" + '' 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 @@ +{ pkgs, ... }: +let + name = "up"; + xclip = "${pkgs.xclip}/bin/xclip"; +in +pkgs.writeScriptBin name + '' + id=$( cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 3 | head -n 1 ) + + if [ $# != 1 ]; then + echo "needs an arg" + else + if [ -f "$1" ]; then + ext="''${1##*.}" + id="$id.$ext" + scp "$1" ferrn:~/www/nerd/uploads/"$id" + echo "https://u.peppe.rs/$id" + echo "https://u.peppe.rs/$id" | ${xclip} -selection clipboard + echo "https://u.peppe.rs/$id" | ${xclip} -i + else + echo "file does not exist" + fi + fi + '' 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 @@ +#! /usr/bin/env bash + +mpv av://v4l2:/dev/video0 \ + --profile=low-latency \ + --untimed \ -- cgit v1.2.3