-
-
Save poloxue/37d3d79b35964ab8d885296b84ab4b5a to your computer and use it in GitHub Desktop.
A small python script for enter a tmux session effectively.
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 python | |
import os | |
output = os.popen("tmux ls -F \\#{session_name}").read() | |
sessions = output.strip().split("\n") | |
print("Sessions:") | |
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" | |
else: | |
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 | |
else: | |
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