Add terminator plugin to search for selected text
This commit is contained in:
parent
777a061efb
commit
42f1017d55
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
vim/.netrwhist
|
||||
vim/bundle/*
|
||||
!vim/bundle/Vundle.vim
|
||||
*.pyc
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
[global_config]
|
||||
enabled_plugins = LaunchpadCodeURLHandler, SearchGoogle, APTURLHandler, GrepEditor, LaunchpadBugURLHandler
|
||||
title_hide_sizetext = True
|
||||
window_state = maximise
|
||||
[keybindings]
|
||||
|
@ -117,6 +118,10 @@
|
|||
type = Terminal
|
||||
uuid = 8eec6a48-cbfb-449c-b49e-704da6e5996d
|
||||
[plugins]
|
||||
[[GrepEditor]]
|
||||
command = vim +{line} {filepath}
|
||||
groups = file line
|
||||
match = ([^ \t\n\r\f\v:]+?):([0-9]+)
|
||||
[profiles]
|
||||
[[default]]
|
||||
background_color = "#060505"
|
||||
|
|
55
config/terminator/plugins/search-google.py
Normal file
55
config/terminator/plugins/search-google.py
Normal file
|
@ -0,0 +1,55 @@
|
|||
import gtk
|
||||
import urllib
|
||||
import terminatorlib.plugin as plugin
|
||||
import re
|
||||
|
||||
# Written by John Cooper http://choffee.co.uk
|
||||
# Copyright 2010 John Cooper
|
||||
# See copyright file that comes with this file for full licence
|
||||
|
||||
# Modified by cgw 2011/11/06
|
||||
|
||||
# AVAILABLE must contain a list of all the classes that you want exposed
|
||||
AVAILABLE = ['SearchGoogle']
|
||||
|
||||
_spaces = re.compile(" +")
|
||||
|
||||
# TODO: move some of the constants into a config object
|
||||
|
||||
class SearchGoogle(plugin.Plugin):
|
||||
capabilities = ['terminal_menu']
|
||||
|
||||
def do_search(self, searchMenu):
|
||||
"""Launch Google search for string"""
|
||||
if not self.searchstring:
|
||||
return
|
||||
base_uri = "http://www.google.com/search?q=%s"
|
||||
uri = base_uri % urllib.quote(self.searchstring.encode("utf-8"))
|
||||
gtk.show_uri(None, uri, gtk.gdk.CURRENT_TIME)
|
||||
|
||||
def callback(self, menuitems, menu, terminal):
|
||||
"""Add our menu item to the menu"""
|
||||
self.terminal = terminal
|
||||
item = gtk.ImageMenuItem(gtk.STOCK_FIND)
|
||||
item.connect('activate', self.do_search)
|
||||
if terminal.vte.get_has_selection():
|
||||
clip = gtk.clipboard_get(gtk.gdk.SELECTION_PRIMARY)
|
||||
self.searchstring = clip.wait_for_text().strip()
|
||||
self.searchstring = self.searchstring.replace("\n", " ")
|
||||
self.searchstring = self.searchstring.replace("\t", " ")
|
||||
self.searchstring = _spaces.sub(" ", self.searchstring)
|
||||
else:
|
||||
self.searchstring = None
|
||||
if self.searchstring:
|
||||
if len(self.searchstring) > 40:
|
||||
displaystring = self.searchstring[:37] + "..."
|
||||
else:
|
||||
displaystring = self.searchstring
|
||||
item.set_label("Search Google for \"%s\"" % displaystring)
|
||||
item.set_sensitive(True)
|
||||
else:
|
||||
item.set_label("Search Google")
|
||||
item.set_sensitive(False)
|
||||
# Avoid turning any underscores in selection into menu accelerators
|
||||
item.set_use_underline(False)
|
||||
menuitems.append(item)
|
Loading…
Reference in New Issue
Block a user