From 735782be32c6fca65a0b2bd8c4310533d57b610a Mon Sep 17 00:00:00 2001
From: ubq323 <ubq323@ubq323.website>
Date: Sun, 16 Apr 2023 12:18:31 +0100
Subject: initial commit of dot files

---
 .local/bin/rupload   | 65 +++++++++++++++++++++++++++++++++++
 .local/bin/rws       | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 .local/bin/status.sh | 52 ++++++++++++++++++++++++++++
 .local/bin/ud        | 49 +++++++++++++++++++++++++++
 4 files changed, 261 insertions(+)
 create mode 100755 .local/bin/rupload
 create mode 100755 .local/bin/rws
 create mode 100755 .local/bin/status.sh
 create mode 100755 .local/bin/ud

(limited to '.local/bin')

diff --git a/.local/bin/rupload b/.local/bin/rupload
new file mode 100755
index 0000000..925fc0e
--- /dev/null
+++ b/.local/bin/rupload
@@ -0,0 +1,65 @@
+#!/bin/sh
+
+if [ $# -eq 0 ]; then
+	printf '%s\n' "usage: $0 [-n] [-x override_ext] <filename>" >&2
+	printf '\t%s\n' "-n: dry run (don't actually upload anything)" >&2
+	printf '\t%s\n' "-x override_ext: set extension to override_ext on uploaded filename" >&2
+	exit 1
+fi
+
+dry_run=0
+while [ $# -gt 1 ]; do
+	if [ "$1" = "-x" ]; then
+		override_ext=".$2"
+		shift 2
+	elif [ "$1" = "-n" ]; then
+		dry_run=1
+		shift
+	fi
+done
+
+if [ ! -f "$1" ]; then
+	printf %s "$1: file does not exist" >&2
+	exit 1
+fi
+
+REMOTE="do"
+URLBASE="https://ubq323.website/files/"
+REMOTEDIR="/srv/web/ubq/files/"
+
+ext="${1#*.}"
+if [ "$ext" = "$1" ]; then
+	ext='.file'
+	bname="$(basename "$1")"
+else
+	ext=".$ext"
+	bname="$(basename "$1" "$ext")"
+fi
+ext=${override_ext:-$ext}
+
+rbname="$(md5sum "$1"|cut -d' ' -f1|tr 'a-z' 'A-Z'|basenc -d --base16|basenc --base64|head -c8)"
+rname="$rbname$ext"
+
+exists_already() {
+	ssh "$REMOTE" stat "$REMOTEDIR$1" 2>/dev/null >/dev/null
+	return $?
+}
+
+while exists_already "$rname"; do
+	printf "%s exists already\n" "$rname"
+	rbname="${rbname}_"
+	rname="$rbname$ext"
+done
+
+printf 'uploading to %s\n' "$rname"
+if [ "$dry_run" -eq 1 ]; then
+	echo dryrun, not uploading anything
+	exit 0
+fi
+
+scp "$1" "${REMOTE}:$REMOTEDIR$rname"
+ssh "$REMOTE" chmod a+r "$REMOTEDIR$rname"
+
+url="$URLBASE$rname"
+printf %s "$url" | wl-copy
+notify-send 'copied url to clipboard' "$url"
diff --git a/.local/bin/rws b/.local/bin/rws
new file mode 100755
index 0000000..ebee83c
--- /dev/null
+++ b/.local/bin/rws
@@ -0,0 +1,95 @@
+#!/bin/sh
+
+# rebecca workspace
+#
+# source this from your shell rc file
+# and also start rws -listen when you start sway
+
+
+WSD=$XDG_RUNTIME_DIR/ws
+mkdir -p $WSD
+
+
+
+wslist () {
+	# list workspaces, most-recently-used first
+	swaymsg -t get_workspaces | jq -rc '.[] | .name' | while read wsn; do
+		wsp=$WSD/"$(printf %s "$wsn" | base64)"
+		dt="$(stat -c '%Y' $wsp 2>/dev/null)"
+		if [ $? -eq 1 ]; then
+			dt=1
+		fi
+		printf "%s\t%s\n" "$dt" "$wsn"
+	done | sort -nr | cut -f2-
+}
+
+_escape() {
+	printf %s "$1" | sed -e 's*\\*\\\\*g' -e 's*"*\\"*g'
+}
+
+workin () {
+	# cds to the given directory, then moves focused window to workspace
+	# with that name
+	if [ ! -d "$1" ]; then
+		printf "not a directory\n" >&2
+		return 1
+	else
+		cd "$1"
+		dirname="$(_escape "$(apwd)")"
+		swaymsg "move container to workspace \"$dirname\""
+		swaymsg "workspace \"$dirname\""
+	fi
+}
+
+
+curws () {
+	# prints name of current workspace
+	swaymsg -t get_workspaces \
+		| jq -rc '.[] | select(.focused==true) | .name'
+}
+gowork() {
+	# cds to working directory for current workspace
+	d="$(curws|sed -e "s*^~*$HOME*")"
+	if [ -d "$d" ]; then
+		cd "$d" || return 1
+	fi
+}
+
+queryws () {
+	# uses bmenu to prompt for a workspace name, then switches to that workspace
+	# or if -m given, moves focused window to that workspace instead
+	wsn="$(wslist | bemenu -p workspace -l100 --fn 'Iosevka Fixed 16' --tf '#df73ff' --hf '#df73ff' --hb '#333333')"
+	[ -z "$wsn" ] && return
+
+	if [ "$1" = "-m" ]; then
+		swaymsg "move container to workspace \"$(_escape "$wsn")\""
+	else
+		swaymsg "workspace \"$(_escape "$wsn")\""
+	fi
+}
+
+
+_onswitch () {
+	wsb=$(printf %s "$1" | base64)
+	touch ${WSD}/$wsb
+}
+# run rws -listen to listen for workspace changes,
+# and keep track of that
+if [ "$1" = "-listen" ]; then
+	swaymsg -rmt subscribe '[ "workspace" ]' | while read line; do
+		wsn="$(printf %s "$line" | jq -rc '.current.name')"
+		printf "%s\n" "$wsn"
+		_onswitch "$wsn"
+	done
+fi
+
+# rws -queryws does the same thing as queryws
+#  because it needs to be runnable from sway cfg in order to keybind something for it
+if [ "$1" = "-queryws" ]; then
+	shift
+	queryws $@
+fi
+
+
+
+
diff --git a/.local/bin/status.sh b/.local/bin/status.sh
new file mode 100755
index 0000000..5bd9e4c
--- /dev/null
+++ b/.local/bin/status.sh
@@ -0,0 +1,52 @@
+#!/bin/sh
+
+puts () {
+	printf %s "$1"
+}
+
+escape () {
+	printf %s "$1" | sed -e 's*\\*\\\\*g' -e 's!"!\\"!g'
+}
+
+block_basic () {
+	printf '{"full_text":"%s"},' "$1"
+}
+block_color () {
+	printf '{"full_text":"%s","color":"%s"},' "$1" "$2"
+}
+
+BDIR=/sys/class/power_supply/BAT0
+
+# header
+printf '%s\n' '{"version":1}'
+puts '['
+
+while true; do
+	puts '['
+
+	volinfo="$(amixer get Master | grep 'Mono:')"
+	vol_level="$(printf %s "$volinfo" | awk -F'[][]' '{print $2}')"
+	vol_enabled="$(printf %s "$volinfo" | awk -F'[][]' '{print $6}')"
+	color="#ffffff"; bl=""; br=""
+	[ "$vol_enabled" = "off" ] && { color="#ffff00"; bl="("; br=")"; }
+	block_color "vol $bl$vol_level$br" "$color"
+
+	bat_status="$(cat $BDIR/status | tr 'a-z' 'A-Z' | head -c 3)"
+	bat_level="$(cat $BDIR/capacity)"
+	color="#ffffff"
+	if [ "$bat_level" -le 10 ]; then
+		color="#ff0000"
+	elif [ "$bat_level" -le 25 ]; then
+		color="#ffff00"
+	fi
+	block_color "$bat_status $bat_level%" "$color"
+
+	date="$(date +'%a %Y-%m-%d %H:%M:%S')"
+	block_basic "$date"
+
+
+	puts '],'
+	sleep 1
+
+done
+
diff --git a/.local/bin/ud b/.local/bin/ud
new file mode 100755
index 0000000..a1a50ac
--- /dev/null
+++ b/.local/bin/ud
@@ -0,0 +1,49 @@
+#!/usr/bin/env python3
+
+# unidump version 0.1.1
+# made by ubq323 in the year 2021
+# please use this software for GOOD, not for EVIL
+
+import unicodedata
+import sys
+
+uniquify = True
+arg=""
+args = sys.argv[1:]
+while len(args) > 0:
+    arg = args.pop(0)
+    if arg[0] != '-' or arg == "--":
+        break
+    if arg == "-a":
+        uniquify = False
+        arg = ""
+
+
+s = arg+" ".join(args)
+
+if len(s) == 0:
+    s = sys.stdin.read()
+
+def row(c):
+    try:
+        name = unicodedata.name(c).rjust(50)
+    except ValueError:
+        name = "?"*50
+
+    number = ("U+"+hex(ord(c))[2:].zfill(4)).rjust(7).upper()
+
+    to_c = c
+    if c == '\n':
+        to_c = ' '
+
+    
+        
+    return f"{to_c} | {unicodedata.category(c)} | {name} | {number}"
+
+seen = set()
+for c in s:
+    if uniquify:
+        if c in seen:
+            continue
+        seen.add(c)
+    print(row(c))
-- 
cgit v1.2.3