summaryrefslogtreecommitdiff
path: root/bin/scripts/switch_window
diff options
context:
space:
mode:
authorA Farzat <a@farzat.xyz>2024-10-25 19:35:40 +0900
committerA Farzat <a@farzat.xyz>2024-11-07 19:35:40 +0900
commitd6a9fcfe0d59c35c8c2338c61f0cbad4bbe4f5ab (patch)
treeeff6a9a2b544351d73425d1a5bf43479167b488b /bin/scripts/switch_window
parent7e905e33bc55d142b4fd32c28cc2be99dfdd3f0b (diff)
downloaddotfiles-d6a9fcfe0d59c35c8c2338c61f0cbad4bbe4f5ab.tar.gz
dotfiles-d6a9fcfe0d59c35c8c2338c61f0cbad4bbe4f5ab.zip
Add scripts I don't often use for reference
Diffstat (limited to 'bin/scripts/switch_window')
-rwxr-xr-xbin/scripts/switch_window17
1 files changed, 17 insertions, 0 deletions
diff --git a/bin/scripts/switch_window b/bin/scripts/switch_window
new file mode 100755
index 0000000..55787bc
--- /dev/null
+++ b/bin/scripts/switch_window
@@ -0,0 +1,17 @@
+#!/usr/bin/env sh
+
+windows=$(wmctrl -xl | tr -s '[:blank:]' | cut -d ' ' -f 3-3,5- | sed 's/^[a-zA-Z0-9-]*\.//')
+
+# Add spaces to align the WM_NAMEs of the windows
+max=$(printf %s\\n "$windows" | awk '{cur=length($1); max=(cur>max?cur:max)} END{print max}')
+
+windows=$(printf %s\\n "$windows" | \
+ awk -v max="$max" \
+ '{cur=length($1); printf $1; \
+ for(i=0; i < max - cur + 1; i++) printf " "; \
+ $1 = ""; printf "%s\n", $0}')
+
+
+target=$(printf %s\\n "$windows" | dmenu -l 10 -i -p switch: | tr -s '[:blank:]' | cut -d ' ' -f 2-)
+
+[ -n "$target" ] && wmctrl -a "$target"