[wiki] [sites] Add dmenu window switcher script || Noah Evans

From: <git_AT_suckless.org>
Date: Fri, 08 Jan 2021 16:45:07 +0100

commit e9eb1e46a9cd7529e5e3296bf4df8cc85a5bc0d4
Author: Noah Evans <noah_AT_nevans.me>
Date: Fri Jan 8 10:44:40 2021 -0500

    Add dmenu window switcher script

diff --git a/tools.suckless.org/dmenu/scripts/index.md b/tools.suckless.org/dmenu/scripts/index.md
index 53244dd5..c9bd9e3a 100644
--- a/tools.suckless.org/dmenu/scripts/index.md
+++ b/tools.suckless.org/dmenu/scripts/index.md
_AT_@ -37,3 +37,4 @@ Download
 command is started in a terminal. i.e. "top!".
 * [dmenu-launch](https://github.com/fsilveir/dmenu-launch): Simple and customizable
 dmenu launcher written in Python for acessing passwords, docs and application shortcuts.
+* [switch](switch): dmenu-based window switcher using wmctrl. If using dwm, requires the [ewmhtags](https://dwm.suckless.org/patches/ewmhtags/) or [focusonnetactive](//dwm.suckless.org/patches/focusonnetactive/) patch to be usefull.
diff --git a/tools.suckless.org/dmenu/scripts/switch b/tools.suckless.org/dmenu/scripts/switch
new file mode 100644
index 00000000..02ca8852
--- /dev/null
+++ b/tools.suckless.org/dmenu/scripts/switch
_AT_@ -0,0 +1,17 @@
+windows=$(wmctrl -xl | tr -s '[:blank:]' | cut -d ' ' -f 3-3,5- | sed 's/^[a-zA-Z0-9-]*\.//' | sort | uniq)
+
+# Add spaces to align the WM_NAMEs of the windows
+max=$(echo "$windows" | awk '{cur=length($1); max=(cur>max?cur:max)} END{print max}')
+
+windows=$(echo "$windows" | \
+ awk -v max="$max" \
+ '{cur=length($1); printf $1; \
+ for(i=0; i < max - cur + 1; i++) printf " "; \
+ $1 = ""; printf "%s
", $0}')
+
+
+target=$(echo "$windows" | dmenu -l 10 -i -p switch: | tr -s '[:blank:]' | cut -d ' ' -f 2-)
+
+if [[ -n $target ]]; then
+ wmctrl -a "$target"
+fi
Received on Fri Jan 08 2021 - 16:45:07 CET

This archive was generated by hypermail 2.3.0 : Fri Jan 08 2021 - 16:49:03 CET