Instantly share code, notes, and snippets.

Embed
What would you like to do?
[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
#!/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