forked from msudgh/terminator-search
-
Notifications
You must be signed in to change notification settings - Fork 0
/
terminator_search.py
43 lines (33 loc) · 1.29 KB
/
terminator_search.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
#!/usr/bin/python
from terminatorlib import plugin, config
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk
from subprocess import call
AVAILABLE = ['TerminatorSearch']
class TerminatorSearch(plugin.MenuItem):
capabilities = ['terminal_menu']
def __init__(self):
self.plugin_name = self.__class__.__name__
self.clipboard = None
self.content = None
def callback(self, menuitems, menu, terminal):
# retrive the context of clipboard
self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_PRIMARY)
self.content = self.clipboard.wait_for_text()
# extract 5 character of the clipboard
content_summary = self.content[0:10].strip()
# make available search item in context menu if the clipboard isn't empty
if len(content_summary) > 0 and content_summary != None:
self.add_submenu(menu, ('Search For %s...' % (content_summary)), terminal)
def add_submenu(self, submenu, name, terminal):
# create menu item
menu = Gtk.MenuItem(name)
# call on_click method while Clicking on menu item
menu.connect("activate", self.on_click, terminal)
# append menu item to context menu
submenu.append(menu)
return menu
def on_click(self, widget, event):
url = 'https://duckduckgo.com/' + self.content
call(["xdg-open", url])