Skip to content

Instantly share code, notes, and snippets.

Last active September 15, 2023 10:39
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
A small python script for enter a tmux session effectively.
#!/usr/bin/env python
import os
output = os.popen("tmux ls -F \\#{session_name}").read()
sessions = output.strip().split("\n")
for index in range(len(sessions)):
print(f"{index} - {sessions[index]}")
input_value = input("Please select a session <Index or Name>(default):")
if input_value.isdigit():
sess_name = sessions[int(input_value)]
elif not input_value:
sess_name = "default"
sess_name = input_value
if sess_name not in sessions:
answer = input(f"New a session `{sess_name}`?(Y/N)")
answer == "Y" and os.system(f"tmux new -s {sess_name}") # pyright: ignore
os.system(f"tmux attach -t {sess_name}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment