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
44 lines (33 loc) · 1.15 KB
/
Copy path__init__.py
File metadata and controls
44 lines (33 loc) · 1.15 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
# -*- coding: utf-8 -*-
"""Evaluate simple JavaScript expressions. Use it with care every keystroke triggers an evaluation."""
import os
import subprocess
from albertv0 import *
from shutil import which
__iid__ = 'PythonInterface/v0.1'
__prettyname__ = 'Node Eval'
__version__ = '1.0'
__trigger__ = 'node '
__author__ = 'Hammed Oyedele'
__dependencies__ = ['node']
if which('node') is None:
raise Exception('"node" is not in $PATH.')
iconPath = os.path.dirname(__file__) + '/nodejs.svg'
def run(exp):
return subprocess.getoutput('node --print "%s"' % exp.replace('"', '\\"'))
def handleQuery(query):
if query.isTriggered:
item = Item(
id=__prettyname__,
icon=iconPath,
completion=query.rawString,
)
stripped = query.string.strip()
if stripped == '':
item.text = 'Enter a JavaScript expression...'
else:
item.text = run(stripped)
item.subtext = run(
'Object.prototype.toString.call(%s).slice(8, -1).toLowerCase()' % stripped)
item.addAction(ClipAction('Copy result to clipboard', item.text))
return item