-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
65 lines (45 loc) · 1.41 KB
/
__init__.py
File metadata and controls
65 lines (45 loc) · 1.41 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
"""VSCode
Open VSCode Workspaces defined in config.json"""
from collections import namedtuple
from unicodedata import name
import albert
import os
import json
__title__ = "VSCode"
__version__ = "0.4.0"
__triggers__ = "vsc "
__authors__ = "@justanotherariel"
__exec_deps__ = ["code-insiders"]
__location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
Workspace = namedtuple("Workspace", ["name", "path"])
def getWorkspaces():
f = open(os.path.join(__location__, "config.json"))
data = json.load(f)
for workspace in data:
# print(workspace)
# albert.info([workspace["name"], workspace["path"]])
yield Workspace(workspace["name"], workspace["path"])
f.close()
def buildItem(ws):
text = f"Open {ws.name}"
commandline = ["code-insiders", ws.path]
iconPath = os.path.join(__location__, "icons/workspace.png")
return albert.Item(
id=f"vscode-{ws.name}",
text=ws.name,
subtext=text,
icon=iconPath,
completion=ws.name,
actions=[albert.ProcAction(text=text, commandline=commandline)],
)
def handleQuery(query):
if not query.isTriggered and query.string == "":
return []
if query.isValid:
workspaces = getWorkspaces()
return [
buildItem(ws)
for ws in workspaces
if query.string.lower() in ws.name.lower()
]
return []