-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoogler.py
34 lines (28 loc) · 1.05 KB
/
googler.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
import sublime
import webbrowser
import sublime_plugin
def google(query=None):
url = "https://www.google.com"
if query:
url += "/search?q=%s" % query
webbrowser.open(url)
class GooglerCommand(sublime_plugin.TextCommand):
def run(self, edit):
for region in self.view.sel():
if region.empty():
google()
else:
selection = self.view.substr(region)
settings = sublime.load_settings("googler.sublime-settings")
if settings.get('includeScope'):
scope = self.view.scope_name(region.begin()).rpartition('.')[2].strip()
qc = settings.get(scope, {})
query = ' '.join(filter(None, [qc.get('prefix') if ('prefix' in qc) else scope, selection, qc.get('suffix')]))
else:
query = selection
self.view.window().run_command("googler_with_edit", { "query": query });
class GooglerWithEditCommand(sublime_plugin.WindowCommand):
def run(self, query):
self.window.show_input_panel('Search for:', query, self.on_done, None, None)
def on_done(self, query):
google(query)