Skip to content

Instantly share code, notes, and snippets.

@Soft
Last active January 23, 2020 14:07
Show Gist options
  • Save Soft/0d4247be659cc6b13c6bc80ea0f9b8e7 to your computer and use it in GitHub Desktop.
Save Soft/0d4247be659cc6b13c6bc80ea0f9b8e7 to your computer and use it in GitHub Desktop.
Swap active tmux pane with the largest pane
#!/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)
}
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment