sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit e9eb1e46a9cd7529e5e3296bf4df8cc85a5bc0d4
parent a345b7003fe83fea07e05a4f0be0f839d1bdc825
Author: Noah Evans <noah@nevans.me>
Date:   Fri,  8 Jan 2021 10:44:40 -0500

Add dmenu window switcher script

Diffstat:
Mtools.suckless.org/dmenu/scripts/index.md | 1+
Atools.suckless.org/dmenu/scripts/switch | 17+++++++++++++++++
2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/tools.suckless.org/dmenu/scripts/index.md b/tools.suckless.org/dmenu/scripts/index.md @@ -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 @@ -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\n", $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