-
Notifications
You must be signed in to change notification settings - Fork 1
/
google.py
executable file
·67 lines (53 loc) · 1.44 KB
/
google.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
#!/bin/env python3
from sys import argv
from helpers import mbrofi
# user variables
# application variables
# launcher variables
msg = "Search on google."
prompt = "google:"
answer=""
sel=""
filt=""
index=0
bindings=[]
# run correct launcher with prompt and help message
launcher_args = {}
launcher_args['prompt'] = prompt
launcher_args['mesg'] = msg
launcher_args['filter'] = filt
launcher_args['bindings'] = bindings
launcher_args['index'] = index
def list_entries():
"""Return entries to be displayed in rofi."""
return([''])
def google(query):
"""Generate google search url from query"""
query.replace(" ", "%20")
if query:
url = "https://www.google.com/search?q=" + query.strip()
print("Opening url in browser: " + query)
mbrofi.xdg_open(url)
else:
print("Empty query.")
def main(launcher_args):
"""Main function."""
while True:
answer, exit = mbrofi.rofi(list_entries(), launcher_args)
if exit == 1:
break
index, filt, sel = answer.strip().split(';')
launcher_args['filter'] = filt
launcher_args['index'] = index
if (exit == 0):
# this is the case where enter is pressed
google(filt)
break
else:
break
if __name__ == "__main__":
if ( len(argv) > 1):
query = ''.join(str(e) + ' ' for e in argv[1:]).strip()
google(query)
else:
main(launcher_args)