forked from albertlauncher/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
61 lines (47 loc) · 1.57 KB
/
Copy path__init__.py
File metadata and controls
61 lines (47 loc) · 1.57 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
# -*- coding: utf-8 -*-
"""List and open your Atom projects.
Synopsis: <trigger> [filter]"""
import os
import re
import time
from pathlib import Path
import cson
from albert import *
__title__ = "Atom Projects"
__version__ = "0.4.0"
__triggers__ = "atom "
__authors__ = "manuelschneid3r"
__exec_deps__ = ["atom"]
__py_deps__ = ["cson"]
projects_file = str(Path.home()) + "/.atom/projects.cson"
iconPath = iconLookup('atom')
mtime = 0
projects = []
def updateProjects():
global mtime
try:
new_mtime = os.path.getmtime(projects_file)
except Exception as e:
warning("Could not get mtime of file: " + projects_file + str(e))
if mtime != new_mtime:
mtime = new_mtime
with open(projects_file) as projects_cson:
global projects
projects = cson.loads(projects_cson.read())
def handleQuery(query):
if not query.isTriggered:
return
updateProjects()
stripped = query.string.strip()
items = []
for project in projects:
if re.search(stripped, project['title'], re.IGNORECASE):
items.append(Item(id=__title__ + project['title'],
icon=iconPath,
text=project['title'],
subtext="Group: %s" % (project['group'] if 'group' in project else "None"),
actions=[
ProcAction(text="Open project in Atom",
commandline=["atom"] + project['paths'])
]))
return items