-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtmux_sessionizer.py
More file actions
41 lines (34 loc) · 898 Bytes
/
tmux_sessionizer.py
File metadata and controls
41 lines (34 loc) · 898 Bytes
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
import sys
from pathlib import Path
import libtmux
import sh
from pyfzf.pyfzf import FzfPrompt
fzf = FzfPrompt()
folders = [
"~/Documents/Arcanite/",
"~/Documents/PolyLAN/",
"~/Documents/Python/",
"~/Documents/Typescript/",
"~/Documents/",
"~/Documents/Games/Minecraft/modded/",
]
available_folders = (
sh.find(
*[Path(f).expanduser() for f in folders]
+ "-mindepth 1 -maxdepth 1 -type d".split(" ")
)
.strip()
.split("\n")
)
selected = fzf.prompt(
["Select a folder to create or switch session to"] + available_folders,
"--cycle --header-lines 1 --tmux center",
)
if not selected:
sys.exit(1)
selected = selected[0]
session_name = selected.split("/")[-1]
srv = libtmux.Server()
if not srv.has_session(session_name):
srv.new_session(session_name, attach=False, start_directory=selected)
srv.switch_client(session_name)