Created
March 21, 2018 01:18
-
-
Save jwintersinger/4a1270af4d1c896a3ff23cc000204c31 to your computer and use it in GitHub Desktop.
This file contains 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 python2 | |
import subprocess | |
def move_window(oldpos, newpos): | |
return subprocess.check_output(['tmux', 'move-window', '-s', str(oldpos), '-t', str(newpos)]) | |
def main(): | |
output = subprocess.check_output(['tmux', 'list-windows']) | |
lines = [l.strip() for l in output.split('\n') if l.strip() != ''] | |
frags = [line.strip().split(': ', 1) for line in output.split('\n') if line.strip() != ''] | |
shell_command = 'bash' | |
frags.sort(key = lambda (idx, rest): rest if '* ' not in rest else shell_command) | |
free_pos = max([int(f[0]) for f in frags]) + 1 | |
for newpos, (oldpos, _) in enumerate(frags): | |
move_window(oldpos, int(newpos) + free_pos) | |
active_idx = None | |
for newpos, (_, rest) in enumerate(frags): | |
actual_pos = newpos + free_pos | |
move_window(actual_pos, newpos) | |
if '* ' in rest: | |
active_idx = newpos | |
subprocess.check_output(['tmux', 'select-window', '-t', str(active_idx)]) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment