-
Notifications
You must be signed in to change notification settings - Fork 1
/
rofi_tmux.py
executable file
·53 lines (41 loc) · 1.1 KB
/
rofi_tmux.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python
import subprocess
import utils
terminal = "alacritty"
def get_sessions() -> list[str]:
"""Get open tmux session"""
sessions: list[str] = utils.run_shell_cmd(
["tmux list-session", "-F '#S'"],
).split()
return sessions
def get_choice(sessions: str) -> str:
"""Get session choice"""
sessions: bytes = "\n".join(sessions).encode()
cmd: list[str] = ["rofi", "-dmenu", '-p "Select existing tmux session"']
choice: str = (
subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE,
)
.communicate(input=sessions)[0]
.decode()
)
return choice
def main():
sessions = get_sessions()
choice = get_choice(sessions)
if len(choice) == 0:
return 0
"""New session with name given in the input"""
subprocess.Popen(
[f"{terminal} -e tmux new-session -A -s {choice}"],
shell=True,
stdin=None,
stdout=None,
stderr=None,
close_fds=True,
)
if __name__ == "__main__":
main()