Last active
January 23, 2020 14:07
-
-
Save Soft/0d4247be659cc6b13c6bc80ea0f9b8e7 to your computer and use it in GitHub Desktop.
Swap active tmux pane with the largest pane
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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