Googling query from anywhere

Luckily for you, tualatrix did a small hack on gnome-terminal and added support to search on Google upon right clicking a message.

You need to add a third-party PPA for it to work though. Run these commands in a terminal:

sudo add-apt-repository ppa:tualatrix/personal
sudo apt-get update
sudo apt-get install gnome-terminal

Once updated, close all terminal windows and reopen again. It will work as intended.

gnome-terminal with Google support hack


Keybind sh -c 'firefox "https://www.google.com/search?q=$(xclip -o)"' in System Settings -> Keyboard -> Custom

Or use the following script which let you edit the mouse selection before googling it.

#!/bin/bash

# get mouse selection
QUERY=$(xclip -o)

# edit selection
QUERY=$(zenity --entry --entry-text="$QUERY" --text='Google')
[ "$?" != 0 ] && exit 0

# search google in firefox (you can use google-chrome, chromium, opera ..)
firefox "https://www.google.com/search?q=${QUERY}"

exit 0

To use this script, copy/paste it in a new text file (gedit ..), and name it whatever you like, eg google_clip.sh. Set execute permission, chmod +x /filepath/google_clip.sh or right-click in Nautilus then Properties -> Permissions -> check Execute. Then keybind it.


I had similar requirements and I found Autokey to be very helpful in being able to search any selected text by activating a python script (below) everytime I pressed a set of keyboard buttons (Ctrl+Shift+G for example).

import webbrowser
base="http://www.google.com/search?q="
phrase=clipboard.get_selection()

#Remove trailing or leading white space and find if there are multiple 
#words. 
phrase=phrase.strip()
singleWord=False
if phrase.find(' ')<0:
    singleWord=True

#Generate search URL. 
if singleWord:
    search_url=base+phrase
if (not singleWord):
    phrase='+'.join(phrase.split())
    search_url=base+phrase

webbrowser.open_new_tab(search_url)

A tutorial on how to use Autokey can be found here: Tutorial