summary refs log tree commit diff
diff options
context:
space:
mode:
-rwxr-xr-xbin/cht10
-rwxr-xr-xbin/cronic30
-rwxr-xr-xbin/jq-table8
-rwxr-xr-xbin/netspeed65
-rwxr-xr-xbin/pwloop43
-rwxr-xr-xbin/randgen6
-rwxr-xr-xbin/sponge34
-rwxr-xr-xbin/term-apply-colors18
-rwxr-xr-xbin/url-launcher20
-rwxr-xr-xbin/vipe6
-rwxr-xr-xbin/wait-online10
-rwxr-xr-xbin/whatismyip6
-rwxr-xr-xbin/wttr7
13 files changed, 261 insertions, 2 deletions
diff --git a/bin/cht b/bin/cht
new file mode 100755
index 0000000..0aac747
--- /dev/null
+++ b/bin/cht
@@ -0,0 +1,10 @@
+#!/bin/sh
+set -eu
+
+if [ $# -lt 1 ]; then
+	topic=$(curl -sSf cht.sh/:list | fzfez)
+else
+	topic=$*
+fi
+
+curl -sSf cht.sh/"$topic"
diff --git a/bin/cronic b/bin/cronic
new file mode 100755
index 0000000..804f803
--- /dev/null
+++ b/bin/cronic
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+set -e
+[ -n "$DEBUG" ] && set -x
+
+guienter=
+while getopts Gh opt; do
+	case "$opt" in
+	G) guienter=1 ;;
+	h | ?)
+		printf "usage: %s [ARGS...]\n" "$(basename "$0")"
+		printf "\n"
+		printf "converts reasonably behaved programs that return a nonzero exit status\n"
+		printf "into the back-asswards behavior cron expects, which is that printing text\n"
+		printf "to stdout means an error occurred and any status code, successful or not,\n"
+		printf "is disregarded.\n"
+		printf "\n"
+		printf "  -G  gui-enter as current user\n"
+		printf "\n"
+		exit 2
+		;;
+	esac
+done
+shift $((OPTIND - 1))
+
+if [ -n "$guienter" ]; then
+	set -- /home/robert/bin/gui-enter "$(id -un)" "$@"
+fi
+
+"$@" 1>&2 || printf "error. check stderr\n"
diff --git a/bin/jq-table b/bin/jq-table
new file mode 100755
index 0000000..55d16fb
--- /dev/null
+++ b/bin/jq-table
@@ -0,0 +1,8 @@
+#!/bin/bash
+tsv=$(jq 'def hdr:to_entries|map(.key); def vals:to_entries|map(.value|tostring); (arrays|[(first|hdr)]+[.[]|vals]) // (objects|[hdr]+[vals])|.[]|@tsv' -r)
+col=$(head -n1 <<<"$tsv" | tr '\t' ',' | tr '[:lower:]' '[:upper:]')
+if [ "$1" = "--headers" ]; then
+	echo "$col"
+	exit 1
+fi
+exec column -s $'\t' --table --table-columns "$col" "$@" <(tail -n+2 <<<"$tsv")
diff --git a/bin/netspeed b/bin/netspeed
new file mode 100755
index 0000000..6db5dc5
--- /dev/null
+++ b/bin/netspeed
@@ -0,0 +1,65 @@
+#!/bin/sh
+
+set -e
+[ -n "$DEBUG" ] && set -x
+
+if [ "$1" = "-h" ] || [ "$1" = "help" ]; then
+	printf "usage: %s\n" "$(basename "$0")"
+	printf "use iperf3 to benchmark connection throughput\n"
+	printf "\n"
+	exit 2
+fi
+
+SERVER=inazuma.moji.moe
+PORT=33000
+
+run_server() {
+	printf "starting server... => %s:%s\n" "${SERVER}" "${PORT}" >&2
+	ssh ${SERVER} -- iperf3 -s -D -1 -p ${PORT}
+	# sleep 3
+}
+
+run_client() {
+	printf "measuring...\n" >&2
+	case $1 in
+	dl) iperf3 -J -c ${SERVER} -p ${PORT} -R ;;
+	ul) iperf3 -J -c ${SERVER} -p ${PORT} ;;
+	esac
+}
+
+place() {
+	iplink=$(ip link | grep UP | cut -d' ' -f2 | tr -d ':' | grep -v lo | head -n1)
+	case "${iplink}" in
+	wlan*) iwctl station "${iplink}" show | grep network | xargs | cut -d' ' -f3- ;;
+	*) printf "?\n" ;;
+	esac
+}
+
+if [ -n "$MANUAL" ]; then
+	run_server
+	set -x
+	exec iperf3 -c ${SERVER} -p ${PORT} "$@"
+fi
+
+# measure download
+run_server
+bps_dl=$(run_client dl |
+	jq -r '.end.sum_received.bits_per_second' |
+	awk '{print $0/1000000}')
+
+printf "DL: %.2f\n" "${bps_dl}" >&2
+
+# measure upload
+run_server
+bps_ul=$(iperf3 -J -c ${SERVER} -p ${PORT} |
+	jq -r '.end.sum_sent.bits_per_second' |
+	awk '{print $0/1000000}')
+
+printf "UL: %.2f\n" "${bps_ul}" >&2
+
+# print results
+printf "%s,COUNTRY,CITY,%s,%.2f,%.2f,LAT,LON\n" \
+	"$(date +%d/%m/%y)" \
+	"$(place)" \
+	"${bps_dl}" \
+	"${bps_ul}"
diff --git a/bin/pwloop b/bin/pwloop
new file mode 100755
index 0000000..866b9e9
--- /dev/null
+++ b/bin/pwloop
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+if [ "$1" = "-h" ]; then
+	echo "usage: pwloop SOURCE TARGET [VOLUME]" >&2
+	exit 1
+fi
+
+source_name=$1
+target_name=$2
+
+volume=0.2
+[ -n "$3" ] && volume=$3
+
+# spawn pwloopback
+pw-loopback \
+	-m '[[FL FR]]' \
+	-g 'pwloop' \
+	--capture-props='media.class=Audio/Sink/Virtual audio.position=[FL FR] node.description="pwloop sink" node.name=pwloop' \
+	--playback-props='media.class=Audio/Source/Virtual audio.position=[FL FR] node.description="pwloop source" node.name=pwloop' \
+	&
+
+# save pid for later
+pwloop_pid=$!
+trap '{ kill $pwloop_pid; }' EXIT
+
+set -x
+
+# set monitor volume prop
+pw-cli set-param "$pwloop_oid" 2 "{ \"monitorVolumes\": [$volume, $volume] }"
+
+# connect ports to pwloop
+pw-link "$(pw-link -o | grep "$source_name" | grep 'FL$')" pwloop:input_FL
+pw-link "$(pw-link -o | grep "$source_name" | grep 'FR$')" pwloop:input_FR
+
+# connect ports from pwloop
+pw-link pwloop:capture_FL "$(pw-link -i | grep "$target_name" | grep -v monitor | grep 'FL$')"
+pw-link pwloop:capture_FR "$(pw-link -i | grep "$target_name" | grep -v monitor | grep 'FR$')"
+
+# get object.id
+pwloop_oid=$(pw-dump | jq -r --arg name "pwloop" --arg s "Audio/Sink/Virtual" \
+	'.[]|select(.type=="PipeWire:Interface:Node" and .info.props["node.name"]==$name and .info.props["media.class"]==$s)|.info.props["object.id"]')
+
+wait
diff --git a/bin/randgen b/bin/randgen
new file mode 100755
index 0000000..cb18995
--- /dev/null
+++ b/bin/randgen
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+set -e
+[ -n "$DEBUG" ] && set -x
+
+head -c 12 /dev/urandom | shasum | cut -d ' ' -f1
diff --git a/bin/sponge b/bin/sponge
new file mode 100755
index 0000000..7d106b4
--- /dev/null
+++ b/bin/sponge
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+set -e
+[ -n "$DEBUG" ] && set -x
+
+append=
+while getopts ah opt; do
+	case "$opt" in
+	a) append=1 ;;
+	h | ?)
+		printf "usage: %s [-ah]\n\n" "$(basename "$0")"
+		exit 2
+		;;
+	esac
+done
+shift $((OPTIND - 1))
+outname=$1
+
+tmpfile=$(mktemp)
+trap '{ rm "$tmpfile"; }' EXIT
+
+cat - >"$tmpfile"
+
+if [ -n "$outname" ]; then
+	(
+		if [ -n "$append" ]; then
+			tee -a "$outname" >/dev/null
+		else
+			tee "$outname" >/dev/null
+		fi
+	) <"$tmpfile"
+else
+	cat "$tmpfile"
+fi
diff --git a/bin/term-apply-colors b/bin/term-apply-colors
new file mode 100755
index 0000000..829ab4f
--- /dev/null
+++ b/bin/term-apply-colors
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+set -e
+[ -n "$DEBUG" ] && set -x
+
+# stolen from https://github.com/lemnos/theme.sh/blob/master/bin/theme.sh
+awk '
+BEGIN {
+	fgesc="\033]10;#%s\007"
+	bgesc="\033]11;#%s\007"
+	curesc="\033]12;#%s\007"
+	colesc="\033]4;%d;#%s\007"
+}
+/^foreground:/ { printf fgesc, substr($2, 2) > "/dev/tty" }
+/^background:/ { printf bgesc, substr($2, 2) > "/dev/tty" }
+/^cursor:/ { printf curesc, substr($2, 2) > "/dev/tty" }
+/^[0-9]+:/ { printf colesc, $1, substr($2, 2) > "/dev/tty" }
+'
diff --git a/bin/url-launcher b/bin/url-launcher
index 02e23be..70b51c8 100755
--- a/bin/url-launcher
+++ b/bin/url-launcher
@@ -1,5 +1,21 @@
 #!/bin/sh
 set -e
 
-wl-copy "$@"
-notify-send --urgency=low "copied" "$@"
+text="$*"
+if [ -z "$text" ]; then
+	read -r text
+fi
+
+wl-copy "$text"
+notify-send --urgency=low "copied" "$text"
+
+set -x
+case "$text" in
+*open.spotify.com*) notify-action -u low -c success -A "onclick=swaymsg exec -- spotify --uri=$text" "spotify link found" "$text" ;;
+
+url-launcher://*)
+	text=$(printf "%s" "$text" | sed -e 's,url-launcher://,,')
+	wl-copy "$text"
+	nuke "$text"
+	;;
+esac
diff --git a/bin/vipe b/bin/vipe
new file mode 100755
index 0000000..05d4eb3
--- /dev/null
+++ b/bin/vipe
@@ -0,0 +1,6 @@
+#!/bin/bash
+tmpfile=$(mktemp /tmp/vipe.XXXXX)
+trap '{ rm -rf "${tmpfile}"; }' EXIT
+cat >"${tmpfile}"
+${EDITOR} "${tmpfile}" </dev/tty >/dev/tty
+cat "${tmpfile}"
diff --git a/bin/wait-online b/bin/wait-online
new file mode 100755
index 0000000..7ad52e1
--- /dev/null
+++ b/bin/wait-online
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+trap '{ exit 0; }' INT
+
+while true; do
+	ping -c3 "${1:-gentoo.org}" &&
+		env BEEP_MSG="online again" beep &&
+		break
+	sleep 1
+done
diff --git a/bin/whatismyip b/bin/whatismyip
new file mode 100755
index 0000000..748b731
--- /dev/null
+++ b/bin/whatismyip
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+set -e
+[ -n "$DEBUG" ] && set -x
+
+curl -sSfL ifconfig.co/json | jq
diff --git a/bin/wttr b/bin/wttr
new file mode 100755
index 0000000..086345b
--- /dev/null
+++ b/bin/wttr
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+set -e
+[ -n "$DEBUG" ] && set -x
+
+echo "Querying wttr.in ..."
+exec env REPORT=1 $HOME/.config/waybar/modules/weather.sh