Last active
October 26, 2017 14:35
-
-
Save goodevilgenius/5545155 to your computer and use it in GitHub Desktop.
[wmctrlplus] A convenience script to make some things easier with wmctrl. Probably your window manager can do this stuff already, though. I don't use it anymore #desktop #obsolete
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
function GetNext() { | |
CURR=$(wmctrl -d | grep '^[[:digit:]]*[[:blank:]]*\*' | sed 's/^\([[:digit:]]*\).*/\1/') | |
LAST=$(wmctrl -d | tail -1 | sed 's/^\([[:digit:]]*\).*/\1/') | |
TOTAL=$(expr $LAST + 1) | |
NEXT=$(expr $(expr $CURR + 1) % $TOTAL) | |
echo $NEXT | |
} | |
function GetPrev() { | |
CURR=$(wmctrl -d | grep '^[[:digit:]]*[[:blank:]]*\*' | sed 's/^\([[:digit:]]*\).*/\1/') | |
LAST=$(wmctrl -d | tail -1 | sed 's/^\([[:digit:]]*\).*/\1/') | |
TOTAL=$(expr $LAST + 1) | |
PREV=$(expr $(expr $CURR - 1) % $TOTAL) | |
[ $PREV -lt 0 ] && PREV=$(expr $TOTAL + $PREV) | |
echo $PREV | |
} | |
function SwitchNext() { | |
wmctrl -s $(GetNext) | |
} | |
function SwitchPrev() { | |
wmctrl -s $(GetPrev) | |
} | |
function MoveNext() { | |
MoveTo $(GetNext) | |
} | |
function MovePrev() { | |
MoveTo $(GetPrev) | |
} | |
function MoveTo() { | |
wmctrl -r :ACTIVE: -t $1 | |
wmctrl -s $1 | |
} | |
case "$1" in | |
next) SwitchNext;; | |
prev) SwitchPrev;; | |
gonext) MoveNext;; | |
goprev) MovePrev;; | |
goto) MoveTo $2;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment