-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEgrep.py
42 lines (33 loc) · 1 KB
/
Egrep.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
from albertv0 import *
import subprocess
import os
# see https://albertlauncher.github.io/docs/extensions/python/
__iid__ = "PythonInterface/v0.1"
__prettyname__ = "Egrep"
__version__ = "0.0.1"
__trigger__ = "egn"
__author__ = "Alexandre Leblanc"
HOME_DIR = os.environ["HOME"]
NOTES_DIR = os.environ.get("NOTES_DIR", os.path.join(HOME_DIR, "notes"))
def handleQuery(query):
if query.isTriggered:
return agregate(query)
def run(query):
process = subprocess.Popen(["egrep", "-r", query, NOTES_DIR], stdout=subprocess.PIPE)
comm_tuples = process.communicate()
return comm_tuples[0].splitlines()
def agregate(query):
results = run(query.string)
items = []
for line in results:
r = line[-(len(line) - len(NOTES_DIR) - 1):]
items.append(
Item(
id=__prettyname__,
text="egrep {0}".format(r),
actions=[
ClipAction("Copied to buffer", r)
]
)
)
return items