Skip to content

Instantly share code, notes, and snippets.

@ianpaul
Last active May 20, 2022 16:06
Show Gist options
  • Save ianpaul/a01191313b52c5e6f46af708139437d3 to your computer and use it in GitHub Desktop.
Save ianpaul/a01191313b52c5e6f46af708139437d3 to your computer and use it in GitHub Desktop.
A Python script to choose from your existing tmux sessions.
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