#!/usr/bin/env bash
DISPLAY_CONFIG=($(i3-msg -t get_outputs | jq -r '.[]|"\(.name):\(.current_workspace)"'))

for ROW in "${DISPLAY_CONFIG[@]}"; do
	IFS=':'
	read -ra CONFIG <<< "${ROW}"
	if [ "${CONFIG[0]}" != "null" ] && [ "${CONFIG[1]}" != "null" ]; then
		echo "moving ${CONFIG[1]} right..."
		if [ "${CONFIG[2]}" != "" ]; then
			i3-msg -- workspace \
				--no-auto-back-and-forth "${CONFIG[1]}:${CONFIG[2]}"
		else
			i3-msg -- workspace --no-auto-back-and-forth "${CONFIG[1]}"
		fi
		i3-msg -- move workspace to output right
	fi
done
