Add various more or less useful scripts - scripts - various script and utils
HTML git clone git://z3bra.org/scripts
DIR Log
DIR Files
DIR Refs
---
DIR commit 2acbfa981421739264c5500ccf897954b0aa978b
DIR parent 5df58c349875d0e42b056bfe99c398b75668d29d
HTML Author: Willy Goiffon <dev@z3bra.org>
Date: Thu, 20 Aug 2026 23:04:15 +0000
Add various more or less useful scripts
Diffstat:
A bd-prochot | 47 +++++++++++++++++++++++++++++++
A braille | 12 ++++++++++++
A emoji | 24 ++++++++++++++++++++++++
A http | 3 +++
A microphone | 2 ++
A plain | 3 +++
A speakers | 57 +++++++++++++++++++++++++++++++
A spinner | 54 +++++++++++++++++++++++++++++++
A urldecode | 2 ++
A urlencode | 33 +++++++++++++++++++++++++++++++
10 files changed, 237 insertions(+), 0 deletions(-)
---
DIR diff --git a/bd-prochot b/bd-prochot
@@ -0,0 +1,47 @@
+#!/bin/sh
+
+# Initial value read 2026-02-26: e4005f
+
+# BD-PROCHOT is a mechanism to protect processor overheating.
+# The side-effect is that is slow the hell out of it by throttling the
+# CPU frequency to its minimum.
+#
+# The model-specific register (MSR) holds the configuration for this
+# feature at address 0x1FC. The last bit defines wether or not BD-PROCHOT
+# will actually throttle o not the CPU.
+#
+# Clearing that last bit unleash the CPU (or rather prevents limiting it).
+
+# Get full register value
+reg="0x$(doas rdmsr 0x1FC)"
+
+usage() {
+ echo "usage: $(basename $0) [-cs]" >&2
+}
+
+bdph_bit() {
+ echo $((reg & 0x000001))
+}
+bdph_set() {
+ echo $((reg | 0x000001))
+}
+bdph_clr() {
+ echo $((reg & 0xfffffe))
+}
+
+while getopts "hcs" OPT; do
+ case "$OPT" in
+ c) v=$((reg & 0xfffffe));;
+ s) v=$((reg | 0x1));;
+ h) usage; exit 0;;
+ *) usage; exit 1;;
+ esac
+done
+shift $((OPTIND-1))
+
+if [ -n "$v" ]; then
+ doas wrmsr 0x1FC $(printf %d $v)
+ doas rdmsr 0x1FC
+else
+ bdph_bit
+fi
DIR diff --git a/braille b/braille
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+case $LANG in
+en_US.*) tbl=en-ueb-g1.ctb;;
+fr_FR.*) tbl=fr-bfu-comp6;;
+esac
+
+if [ "$1" = "-d" ]; then
+ lou_translate fr-bfu-comp6.utb,unicode-braille.utb
+else
+ lou_translate unicode-braille.utb,fr-bfu-comp6.utb
+fi
DIR diff --git a/emoji b/emoji
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+spec='https://unicode.org/Public/emoji/14.0/emoji-test.txt'
+cache=$HOME/.cache/emoji.txt
+
+sync() {
+ curl -sL $spec \
+ | sed '/^#/d;/^$/d' \
+ | grep fully-qualified \
+ | sed 's/.*#\s*//;s/\s*E[0-9.]\+\s*/\t/;/:/d' \
+ > $cache
+}
+
+[ -f $cache ] || sync
+
+if tty -s; then
+ pick < $cache | cut -f1
+elif [ -n "$WAYLAND_DISPLAY" ]; then
+ sed 's/\t/ /' $cache \
+ | tofi --prompt-text "emoji" \
+ | sed -r 's/\s+.*$//' | tr -d '\n' | wl-copy
+else
+ cat $cache
+fi
DIR diff --git a/http b/http
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+plumb -u https://http.cat/${1:-418}
DIR diff --git a/microphone b/microphone
@@ -0,0 +1 @@
+speakers
+\ No newline at end of file
DIR diff --git a/plain b/plain
@@ -0,0 +1,3 @@
+#!/bin/sed -f
+
+s/\[[^m]\+m//g
DIR diff --git a/speakers b/speakers
@@ -0,0 +1,57 @@
+#!/bin/sh
+
+export LC_ALL=C
+
+usage() {
+ echo "usage: $(basename $0) [-c sink/source] [volume%|toggle]" >&2
+}
+
+muted() {
+ pactl get-${control}-mute $1|cut -d' ' -f2
+}
+
+getvolume() {
+ pactl get-${control}-volume $1|grep -Eo "[0-9]+%"|uniq
+}
+
+setvolume() {
+ pactl set-${control}-volume $1 $2
+}
+
+togglevolume() {
+ pactl set-${control}-mute $1 toggle
+}
+
+# default to output management
+control=sink
+
+while getopts "hc:" OPT; do
+ case $OPT in
+ c) control="$OPTARG";;
+ h) usage; exit 0;;
+ *) usage; exit 1;;
+ esac
+done
+
+shift $((OPTIND - 1))
+
+case $(basename $0) in
+speakers) control=sink ;;
+microphone) control=source ;;
+esac
+
+# get default controlled device
+target=$(pactl get-default-${control})
+
+if [ "$#" -eq 0 ]; then
+ case $(muted $target) in
+ yes) echo off ;;
+ no) getvolume $target ;;
+ esac
+ exit
+fi
+
+case $1 in
+toggle|-) togglevolume $target ;;
+*) setvolume $target $1 ;;
+esac
DIR diff --git a/spinner b/spinner
@@ -0,0 +1,54 @@
+#!/bin/sh
+#
+# Display a spinner for as long as a lockfile is taken.
+# Take a lock with flock(1):
+# flock /tmp/sleep.lock sleep 20 &
+# spinner /tmp/sleep.lock
+
+# https://antofthy.gitlab.io/info/ascii/Spinners.txt
+randspin() {
+ n=4
+ c=${1:-$(seq $n|shuf|head -n1)}
+ case $c in
+ worm|1) echo "⠋ ⠙ ⠹ ⠸ ⢰ ⣰ ⣠ ⣄ ⣆ ⡆ ⠇ ⠏" ;;
+ hole|2) echo "⣾ ⣽ ⣻ ⢿ ⡿ ⣟ ⣯ ⣷" ;;
+ sand|3) echo "⠁ ⠂ ⠄ ⡀ ⡈ ⡐ ⡠ ⣀ ⣁ ⣂ ⣄ ⣌ ⣔ ⣤ ⣥ ⣦ ⣮ ⣶ ⣷ ⣿ ⡿ ⠿ ⢟ ⠟ ⡛ ⠛ ⠫ ⢋ ⠋ ⠍ ⡉ ⠉ ⠑ ⠡ ⢁" ;;
+ leap|4) echo "⣀ ⢄ ⢂ ⢁ ⡈ ⡐ ⡠" ;;
+ esac
+}
+
+usage() {
+ echo "usage: $(basename $0) [-s spinner] [-p prefix] lockfile" >&2
+}
+
+spinner=$(randspin)
+while getopts "hp:s:" OPT; do
+ case "$OPT" in
+ s) spinner=$(randspin $OPTARG);;
+ p) prefix="$OPTARG";;
+ h) usage; exit 0;;
+ *) usage; exit 1;;
+ esac
+done
+shift $((OPTIND - 1))
+
+if [ $# -ne 1 ]; then
+ usage
+ exit 1
+fi
+
+# Exit immediately if lockfile doesn't exists
+[ -e "$1" ] || exit
+
+printf '%s[?25l ' "$prefix"
+trap "printf '[?25h\b🗸\n'; exit" EXIT INT
+until flock -n "$1" true; do
+ for c in $spinner; do
+ if flock -n "$1" true; then
+ exit 0
+ else
+ printf "\b%s" "$c"
+ sleep 0.08
+ fi
+ done
+done
DIR diff --git a/urldecode b/urldecode
@@ -0,0 +1 @@
+urlencode
+\ No newline at end of file
DIR diff --git a/urlencode b/urlencode
@@ -0,0 +1,33 @@
+#!/bin/sh
+
+usage() {
+ echo "usage: $(basename $0) [-hde]" >&2
+}
+
+urlencode() {
+sed 's/\n$//'|od -t d1 | awk '{
+ for (i = 2; i <= NF; i++) {
+ printf(($i>=48 && $i<=57) || ($i>=65 && $i<=90) || ($i>=97 && $i<=122) ||
+ $i==45 || $i==46 || $i==95 || $i==126 ?
+ "%c" : "%%%02x", $i)
+ }
+}'
+echo
+}
+
+urldecode() {
+ perl -pe 's/\+/ /g; s/%([0-9a-f]{2})/chr(hex($1))/eig'
+}
+
+fn=$(basename $0)
+
+while getopts 'hde' OPT; do
+ case $OPT in
+ e) fn=urlencode;;
+ d) fn=urldecode;;
+ h) usage; exit 0;;
+ *) usage; exit 1;;
+ esac
+done
+
+$fn