Last active
May 20, 2022 16:06
-
-
Save ianpaul/a01191313b52c5e6f46af708139437d3 to your computer and use it in GitHub Desktop.
A Python script to choose from your existing tmux sessions.
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
import subprocess | |
def pick_tmux(): | |
print("Here are your active tmux sessions:\n") | |
s = subprocess.run(["tmux", "ls"], capture_output=True, text=True).stdout.strip("\n") | |
seshes = s.splitlines() | |
pretty_list = [s [:s.find(":")] for s in seshes] | |
put_numbers = enumerate(pretty_list, start=1) | |
menu_dict=dict((i,j) for i,j in put_numbers) | |
for key, value in menu_dict.items(): | |
print(key, value) | |
txt = int(input("Choose the session number you'd like to run.\n")) | |
subprocess.run(["tmux", "attach-session", "-t", menu_dict[txt]]) | |
pick_tmux() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment