Search with Google in the terminal

The word google is used as both a noun and a verb. Google is now accepted as a verb in standard English. Typically, Google searches are executed in a browser. The small tool Googler provides the user with an alternative that moves a Google search to the command line. Before dismissing the Googler approach as a silly gimmick, you should consider the advantages for certain users discussed here.

The command line has a reputation for being a mere relic of the past. Supposedly, there is no place among modern Linux distributions for such an archaic way of working. It may in fact be true that a modern Linux system can be operated entirely from the graphical interface and that this is a positive development. Even so, administrators and other computer workers place a great deal of value on working in the terminal. During the course of a long career, I have integrated both approaches according to the circumstances at hand. Googler is a perfect match for working in the terminal. I have been working with the program for several weeks now and am getting more and more enthusiastic about using it.

New Tool

Googler [1] is still a new tool that has not found an entry point into all distributions. A Debian package [2] exists for other Debian derivatives, such as Ubuntu and Linux Mint. Although Googler can be installed from the archive with Ubuntu, it is not available there in the current version 2.7.1. It is probably a good idea for you to use the current package. Once downloaded, it can be installed with dpkg -i googler_2.7-1_all.deb and modified as appropriate. Googler can also be installed directly from the Git archive (Listing 1).

Listing 1

Installing Googler

$ cd /tmp
$ git clone https://github.com/jarun/googler/
$ cd googler
$ sudo make install
$ cd auto-completion/bash/
$ sudo cp googler-completion.bash /etc/bash_completion.d/

Ready to use

The last two commands make sure that auto complete is useable. When installed via the package management, the application gets updated at the same time. When installing from Git, the command

sudo googler -U

pulls in an updated version. Googler can also be started directly from the folder, thus without being installed. To do this, enter ./googler . The coloration for the output is subdued, but it can be modified with the color codes found on GitHub under the heading Colors [3].

Googler gets along without a configuration file. Specifying a particular default setting works via an alias. These can be set up in the .bashrc file in the home directory, or otherwise universally for all users in /etc/bash.bashrc . For example, if you enter the line

alias g='googler -n 5 -c en -l com'

at the end of these files and then also enter the

g <search term>

on the command line, you will get the first five English language references for the top-level .com domain.

Configuring

It is also possible to set up multiple aliases and assign labels of your choice. These could be for example g1 , g2 or gde , gus , etc. Once a new alias is saved, you can issue the command source .bashrc to activate them. You can temporarily bypass defined aliases on the command line outside of the omniprompt with a different construction such as:

g -n 20 -l us -c org <search term>

You can exit the omniprompt by pressing Ctrl+D.

Once installation is complete, Googler is ready to use. After entering googler without any further input, you will find yourself in the so-called omniprompt (Figure 1). This makes sense when you want to start more than one search. If you want to google for a single term, you can also enter:

Figure 1: The omniprompt can remain open all of the time in your terminal window.
googler <search term>

In the omniprompt, on the other hand, you only need to enter the search term itself (Figure 2). There is some useful advice you can access if you use the question mark, including for example using the n(ext) and p(revious) keys to scroll forwards and backwards through search results.

Figure 2: A simple search without parameters produces 10 search results.

Browsing Around

The search results produced are numbered consecutively. You only need enter and confirm the corresponding number in the browser in order to display one of the results. Your default browser will then open with the desired web page (Figure 3).

Figure 3: Entering the corresponding number opens the web page the user wants.

This also works outside of a graphical interface if you have installed a text browser like Links2 , Lynx or Elinks . Click on the yellow-colored URL if the option for opening URLs has been activated in the terminal. If a search term is entered incorrectly, the Google search engine generally corrects the mistake. However, corrections are not desired in some situations. If for instance you enter googler googler , the search engine will incorrectly change this to a search for the term "Google."

Parameters

In order to prevent Google's autocorrect, you can specify that the search term is valid exactly as entered. This approach works most of the time, but not always. For instance, the entry googler -x googler should produce the desired result. Unfortunately, the switch for this search term does not work. Results for Google are displayed instead of those for Googler. However, other searches that are entered with an -x are not autocorrected.

You can also limit a search to a particular website. The -w switch restricts the scope of the search. The second result for

googler -w ubuntu-user.com cryptography

for example, is an introductory piece for Ubuntu User #27 (Figure 4).

Figure 4: The search can be limited to a single website.

You can also access Google News with Googler. The -N switch works here to fish out the current news for the search term you enter (Figure 5). Googler knows many other switches for controlling a search. The list of all of the parameters [4] (see Table 1) and a selection of examples [5] is helpful for getting acquainted with the entire collection of options.

Figure 5: You can also browse through Google News.

Table 1

Parameters in Googler

Parameter Function
-n<number> Show n sources (default = 10)
-N Show sources from Google News
-c <TLD> Show country-specific sources by TLD (-c .com )
-l <LANG> Show sources in this language (-l en )
-x Exact result, no autocorrection (not correctly implemented)
-C No colored output
-j Open the first result in the browser
-t <xn> Time limit (h5 = 5 hours, d5 = 5 days, w5 = 5 weeks, m5 = 5 months, y5 = 5 years)
See [4] for additional parameters

Conclusion

If you work part of the time in the terminal and keep at least one open, this tool could become a favorite. It helps you gain an overview of the results for a search and keeps distractions at bay. If you have also defined some aliases, you can work faster than with any other method. Frequent Google users will find a tool, when used correctly, saves a lot of time in both the home and the professional setting. I am giving it a big thumbs up.