Last Updated on September 1, 2020
I love working with the command line. Seriously, I think there’s hardly anything more productive and versatile for a software developer than the terminal. Maybe it’s the hacker in me. Don’t get me wrong, I’m a heavy user of graphical applications, but the terminal will always have a special place.
I’ve recently come across a command-line tool that’s right up my street. It’s called googler, an open source tool to Google from the command-line. It’s written in Python, so that ticks another box for me. googler isn’t affiliated to Google in any way.
Installation
The tool is easy to install even for beginners, as the developer provides packages for Ubuntu, Debian, openSUSE, Fedora, and CentOS distros. There’s the usual tarball for the more adventurous. The snapcrafters have also produced a snap for the tool.
In operation
So what does googler do? This tool lets you search Google Web and Google News from the command-line the way *you* want. Searches display the title, URL, and abstract for each result, which can be directly opened in a browser (text or graphical), from the terminal. The results are fetched in pages, and there’s page navigation too.
By default I have searches open in the w3m text browser. Add the following line to the ~/.bashrc file.
Other text-browsers are supported such as links, lynx, elinks, but I was unable to get the browsh web browser working with googler. With browsh, searches only went to the home page.
At the googler prompt, there’s a lot of power at your fingertips with googler’s omnikeys. Let’s explore a few of my favorites.
omnikeys
u
One bugbear is that, by default, googler doesn’t show search results that necessarily fit in the terminal’s height, so you may have to scroll back to see the first hits. The simplest way is mitigate this issue is to start googler with the option -n X where X is the number of results to show on a page. For my default terminal size, googler -n 8 gives a good outcome, but for the purposes of the images below I’ve gone with 5 results per page.
As you can see, the URL for each match takes up its own line, therefore reducing the number of matches for a given display size.
Exercise the power of the omnikey u.
This toggles on the domain name only on searches. As this reduces the length of URL addresses, more search entries appear on a single page.
O
Sometimes, there’s 1 or more searches I want to view in a graphical web browser. That’s easy. The O omnikey comes into play. Say I want to view the first 3 results in a graphical browser (overriding my usual default of opening results in w3m). Simply type:
Each search is opened in a separate tab in the web browser.
The other omnikeys
There’s keys to fetch the next or previous set of search results, go back to the first page, and more. Here’s the full list of omnikeys.
Google News
googler also supports Google News. At the command-line, this is invoked by typing:
or
Search a site using Google
Say I want to limit my searches to linuxlinks.com.
At the command-line type:
Other features include:
- Fast and clean. There’s no ads, stray URLs, or clutter stopping you getting things done.
- Customize the color scheme via a six-letter string, reminiscent of BSD LSCOLORS.
- Search and option completion scripts for Bash, Zsh and Fish shells.
- Search and exit without a prompt. This means you can easily embed the output in other software. That’s one of the strengths of command-line software in general.
- Fetch n results in a go, start at the nth result.
- Disable automatic spelling correction and search exact keywords
- Time-limit searches – you can specify the number of hours, days, weeks, months, or years.
- Country-specific search with to-level domain (default: worldwide/.com)
- Display output in different languages.
- Google keywords (e.g. filetype:mime, site:somesite.com) support.
- Open the first result directly in browser with googler -j.
- HTTPS proxy, User Agent, TLS 1.2 (default) support.
- Output in JSON format.
- Comprehensive documentation, a man page with useful usage examples.
- Minimal dependencies with only Python needed.
Web site: github.com/jarun/googler
Developer: Arun Prakash Jana
License: GNU General Public License v3.0
googler is written in Python. Learn Python with our recommended free books and free tutorials.
The developer has also written a separate command-line utility to search DuckDuckGo from the terminal.