dotfiles

Configuration for the software I use.
git clone https://git.sr.ht/~jbauer/dotfiles
Log | Files | Refs | README | LICENSE

commit 2876b9d63b43722c8c8dec2521ea57310aed00b9
parent 5f3cbc1ed899a2565f37a5aadba1d317ddeba17c
Author: Jake Bauer <jbauer@paritybit.ca>
Date:   Mon, 18 Oct 2021 03:59:20 -0400

Consolidate scripts into this repo

Diffstat:
A.local/bin/flac-to-mp3.sh | 27+++++++++++++++++++++++++++
A.local/bin/git-apply-patch | 16++++++++++++++++
A.local/bin/optimizeimg | 43+++++++++++++++++++++++++++++++++++++++++++
A.local/bin/qrkey | 18++++++++++++++++++
A.local/bin/stream-countdown | 25+++++++++++++++++++++++++
5 files changed, 129 insertions(+), 0 deletions(-)

diff --git a/.local/bin/flac-to-mp3.sh b/.local/bin/flac-to-mp3.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +MUSICDIR="/home/jbauer/media/audio/music-mp3" +MAXJOBS=$(nproc) + +convert() +{ + for thing in "$@"; do + if [ -d "$thing" ]; then + convert "$thing"/* + else + if [ "$numJobs" -gt "$MAXJOBS" ] || [ "$numJobs" -eq "$MAXJOBS" ]; then + wait -n; + numJobs=$((numJobs-1)) + fi + fileName=$(basename -s .flac "$thing") + dirName=$(dirname "$thing") + mkdir -vp "$MUSICDIR/$dirName" + ffmpeg -y -hide_banner -i "$thing" -q:a 1 \ + "$MUSICDIR/$dirName/$fileName".mp3 & + numJobs=$((numJobs+1)) + fi + done +} + +numJobs=0 +convert "$@" diff --git a/.local/bin/git-apply-patch b/.local/bin/git-apply-patch @@ -0,0 +1,16 @@ +#!/bin/sh + +projectsDir="$HOME/Documents/projects" +patchFile="/tmp/patch" + +IFS='' +while read -r line; do + echo "$line" >> "$patchFile" + if echo -n "$line" | grep -q "^Subject:"; then + repo=$(echo "$line" | grep -o '\[PATCH .*\]' | cut -d' ' -f2 | tr -d ']') + fi +done + +echo "Applying patch to: $projectsDir/$repo" +cd "$projectsDir"/"$repo" && git am "$patchFile" +rm "$patchFile" diff --git a/.local/bin/optimizeimg b/.local/bin/optimizeimg @@ -0,0 +1,43 @@ +#!/bin/sh + +optimizejpg() +{ + convert \ + -sampling-factor 4:2:0 \ + -strip -quality 85 \ + -interlace JPEG \ + -colorspace RGB \ + "$file" \ + "$filename"-optimized.jpg + exiftool -all= "$filename"-optimized.jpg + rm "$filename"-optimized.jpg_original +} + +optimizepng() +{ + if [ ! -x $(command -v optipng) ]; then + echo "Optimizing PNGs requires the optipng program." + exit 1 + fi + optipng -out "$filename"-optimized.png "$file" + exiftool -all= "$filename"-optimized.png + rm "$filename"-optimized.png_original +} + +for file in "$@"; do + if [ -f "$file" ]; then + case "$file" in + *.jpg) filename=$(basename "$file" .jpg); optimizejpg ;; + *.JPG) filename=$(basename "$file" .jpg); optimizejpg ;; + *.jpeg) filename=$(basename "$file" .jpeg); optimizejpg ;; + *.JPEG) filename=$(basename "$file" .jpeg); optimizejpg ;; + *.png) filename=$(basename "$file" .png); optimizepng ;; + *.PNG) filename=$(basename "$file" .png); optimizepng ;; + *) + filename=$(basename "$file" .png) + echo "The provided file is not a JPG or PNG, it will be converted to a PNG and optimized with optipng." + optimizepng + ;; + esac + fi +done diff --git a/.local/bin/qrkey b/.local/bin/qrkey @@ -0,0 +1,18 @@ +#!/bin/sh + +# Requires qrencode and ImageMagick +# Written on OpenBSD, portability not tested yet + +cwd="$(pwd)" +mkdir -p /tmp/qrkey +cd /tmp/qrkey +split -b 1000 "$1" splitkey- + +order=1 +for file in splitkey-*; do + qrencode -r "$file" -d 150 -t png -o "$order".png + order=$((order+1)) +done + +convert *.png "$cwd"/"$(basename $1)"-qrcodes.pdf +rm splitkey-* *.png diff --git a/.local/bin/stream-countdown b/.local/bin/stream-countdown @@ -0,0 +1,25 @@ +#!/bin/sh + +# Start at 10:00 or the provided number of minutes +minutes="$1" +minutes="${minutes:=10}" +seconds=0 + +# Give the stream a moment to start +printf " %02d:%02d" "$minutes" "$seconds" > /tmp/countdown_timer.txt +printf "Nothing Playing" > /tmp/stream-music.txt +gnome-terminal -- cava & + +while true; do + sleep 1 + rhythmbox-client --print-playing-format="%tt by %ta — %te/%td" > /tmp/stream-music.txt + if [ "$minutes" -eq 0 ] && [ "$seconds" -eq 0 ]; then + printf "Starting Soon" > /tmp/countdown_timer.txt + continue + elif [ "$seconds" -eq 0 ]; then + seconds=59 + minutes=$((minutes-1)) + fi + printf " %02d:%02d" "$minutes" "$seconds" > /tmp/countdown_timer.txt + seconds=$((seconds-1)) +done