Skip to content

Instantly share code, notes, and snippets.

@goodevilgenius
Last active October 26, 2017 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goodevilgenius/5545155 to your computer and use it in GitHub Desktop.
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
#!/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