-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtmux_firefox_groups.py
More file actions
65 lines (49 loc) · 1.49 KB
/
tmux_firefox_groups.py
File metadata and controls
65 lines (49 loc) · 1.49 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
import argparse
import configparser
import os
import subprocess
import sys
from pathlib import Path
from pyfzf.pyfzf import FzfPrompt
parser = argparse.ArgumentParser()
parser.add_argument(
"--no-open",
action="store_true",
help="Do not open firefox window. Mostly for debugging",
)
parser_args = parser.parse_args()
BASE_PATH = Path("~/.firefox/").expanduser()
configs = {}
sections = {}
for subconffile in os.listdir(BASE_PATH):
if not subconffile.endswith(".ini"):
continue
prefix = subconffile.replace(".ini", "").capitalize()
config = configparser.ConfigParser()
config.read(BASE_PATH / subconffile)
configs[subconffile] = config
for section in config.sections():
section_name = f"[{prefix}] {section}"
sections[section_name] = {
"section": section,
"config": subconffile,
}
fzf = FzfPrompt()
selections = fzf.prompt(
["Select one or more group to open"] + list(sections.keys()),
"--cycle --multi --header-lines 1",
)
if not selections:
sys.exit(0)
for selected_group in selections:
info = sections[selected_group]
config = configs[info["config"]]
prefix = config[info["section"]].get("prefix", "")
suffix = config[info["section"]].get("suffix", "")
endpoints = [
f"{prefix}{e}{suffix}" for e in config[info["section"]]["endpoints"].split("\n")
]
data = ["firefox"]
for endpoint in endpoints:
data.extend(["--new-tab", endpoint])
subprocess.Popen(data)