summaryrefslogtreecommitdiff
path: root/bin/rws
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-04-28 02:30:33 +0100
committerubq323 <ubq323@ubq323.website>2023-04-28 02:30:33 +0100
commit6e3a1f376fbef9d0f6f8c72d6b22ff1d40e812ed (patch)
tree10829dd8d7c7125d511c270ba392e5c5812114d8 /bin/rws
parent4762791fad362c8afe1c9a2b1c555c6a8d7b79d1 (diff)
movement
Diffstat (limited to 'bin/rws')
-rwxr-xr-xbin/rws99
1 files changed, 99 insertions, 0 deletions
diff --git a/bin/rws b/bin/rws
new file mode 100755
index 0000000..7041e8c
--- /dev/null
+++ b/bin/rws
@@ -0,0 +1,99 @@
+#!/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
+}
+renws () {
+ # renames current ws to current working dir
+ swaymsg "rename workspace to $(apwd)"
+}
+
+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
+
+
+
+