#!/usr/bin/env bash tmux list-panes | awk ' BEGIN { largest_area=0 largest_id=0 active_id=0 } match($2, /\[([0-9]+)x([0-9]+)\]/, dim) { area=dim[1]*dim[2] if (area > largest_area) { largest_area=area largest_id=substr($1, 1, length($1)-1) } } /(active)/ { active_id=substr($1, 1, length($1)-1) } END { if (largest_id != active_id) { system("tmux swap-pane -d -s " active_id " -t " largest_id) } } '