-
Notifications
You must be signed in to change notification settings - Fork 1
/
__init__.py
70 lines (59 loc) · 1.77 KB
/
__init__.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# -*- coding: utf-8 -*-
'''Converter for currency, units and calculator.
Current backends: fixer.io.
Synopsis: "10 dollars to eur, cad" "10 meters to inches" "10 + sqrt(2)" "cos(pi + 3i)"'''
# Uncomment below to set keyword to files (leave a space after keyword)
__triggers__ = '?'
__title__ = 'Files'
__version__ = '0.0.1'
__authors__ = 'Tilemachos Charalampous'
__exec_deps__ = ['xdg-open']
__py_deps__ = ['pathspec']
TRIGGERS = globals().get('__triggers__') or []
import os
import sys
MAIN_DIR = os.path.realpath(os.path.dirname(__file__))
sys.path.append(MAIN_DIR)
from files.launcher import Launcher
Launcher.set('albert')
from files.service import FilesService
from files.icon import IconRegistry
from albert import ProcAction, Item
home = os.path.expanduser('~')
replace_home = lambda path: path.replace(home, '~', 1)
def initialize():
FilesService().load_settings_albert(os.path.join(MAIN_DIR, 'settings.ini'))
FilesService().run()
def finalize():
FilesService.stop()
def handleQuery(query):
if TRIGGERS and not query.isTriggered:
return
query_str = query.string
if not query_str:
return
query.disableSort()
results = FilesService().search(query_str)
items = []
for result in results:
name = result.name
path = result.path
icon = IconRegistry().get_icon(result)
text = name
subtext = replace_home(path)
actions = [
ProcAction(
text='Open {}'.format(path),
commandline=['xdg-open', path],
),
]
items.append(Item(
id=__title__,
icon=icon,
text=text,
subtext=subtext,
actions=actions
))
if not items:
return None
return items