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
43 lines (32 loc) · 1.07 KB
/
Copy path__init__.py
File metadata and controls
43 lines (32 loc) · 1.07 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
# -*- coding: utf-8 -*-
"""Evaluate simple PHP 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__ = 'PHP Eval'
__version__ = '1.0'
__trigger__ = 'php '
__author__ = 'Hammed Oyedele'
__dependencies__ = ['php']
iconPath = os.path.dirname(__file__) + '/php.svg'
if which('php') is None:
raise Exception('"php" is not in $PATH.')
def run(exp):
return subprocess.getoutput('php -r "%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 PHP expression...'
else:
item.text = run('echo %s;' % stripped)
item.subtext = run('echo gettype(%s);' % stripped)
item.addAction(ClipAction('Copy result to clipboard', item.text))
return item