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/rws | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 95 insertions(+)
 create mode 100755 .local/bin/rws

(limited to '.local/bin/rws')

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
+
+
+
+
-- 
cgit v1.2.3