#!/bin/sh
# Move windows according to my workflow. Check bin/gnome-set-config to
# see its key-binding. Needs wmctrl.

# Move all windows to the primary display. If they're on the secondary
# display, and we try to move them to a workspace, it won't work.
for window_id in $(wmctrl -l | awk '{print $1}'); do
    wmctrl -i  -r $window_id -e 0,0,0,-1,-1
done

# Assign windows to predetermined workplaces
misc=$(wmctrl -l |  awk '/isco|eepa/ {print $1}')
main="$(wmctrl -l  | awk '/ main$/ {print $1}')"
communications="$(wmctrl -l |  awk '/Webex|Slack|communications|notmuch|elfeed/ {print $1}')"
terminals="$(wmctrl -l  | awk '/Alacritty|terminal/ {print $1}')"
browsers="$(wmctrl -l  | awk '/Firefox|Chrom/ {print $1}')"

for window_id in $misc; do
    wmctrl -i -r $window_id -t 4
done

for window_id in $main; do
    wmctrl -i -r $window_id -t 0
done

for window_id in $browsers; do
    wmctrl -i -r $window_id -t 1
done

for window_id in $communications; do
    wmctrl -i -r $window_id -t 2
done

for window_id in $terminals; do
    wmctrl -i -r $window_id -t 3
done