6

At times when I am working on my terminal I run into some errors. To resolve these I have to manually paste the error message to google and search for a solution.

Is it possible to select the message and right click to get a "Google it" option rather than having to manually paste and search?

I am not asking about performing a Google search from the terminal or browsing the web from the terminal. What I want is something more general. I want to be able to select a piece of text and get a "Google selected text" with a right-click (or with a keyboard shortcut). I would prefer the search to take place in a browser.

3 Answers 3

7

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

0
6

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.

2
  • How do I use this script? Commented Nov 7, 2012 at 12:09
  • You bind the script to a key using keyboard shortcuts (dash). It will pick up selected text and load the query in firefox
    – Nemo
    Commented Nov 7, 2012 at 12:11
2

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .