Skip to content

ChiangFamily/googler

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

googler

Screenshot

googler is a command-line power tool to search Google (Web & News) from the terminal. It shows the title, URL and text context for each result. Results are fetched in pages. Next or previous page navigation is possible using keyboard shortcuts. Results are indexed and a result URL can be opened in a browser using the index number. Supports sequential searches in a single instance.

googler is GPLv3 licensed. It doesn't have any affiliation to Google in any way.

Why not use Google provided APIs? Check point 2 in Notes.

If you find googler useful, please consider donating via PayPal.
Donate Button with Credit Cards

Features

  • Uses HTTPS connection
  • Fetch n results in a go
  • Start at nth result
  • Fetch and navigate next or previous set of results
  • Continuous search: fire new searches without exiting
  • Reconnect on new search even if connection is closed due to inactivity
  • Easily open result URLs in browser from cmdline using index number
  • Browser (Chromium and Firefox based) errors and warnings suppression
  • Show full contextual text snippet in search results
  • Specify search duration (in hours / days / weeks / months / years)
  • Fetch results from Google News section
  • Country/domain specific search (28 top-level domains supported, default: .com)
  • Google search keywords like filetype:mime, site:somesite.com etc. work.
  • Open filetype specific links in browser, the links are handled by browser for the type
  • Optionally open the first result directly in browser (as in I'm Feeling Lucky)
  • Specify language preference for results
  • Handle first level of Google redirections (reports IP blocking by Google)
  • Unicode in URL works
  • Skip links to Google News, Images or blank URLs in web search results
  • UTF-8 request and response
  • Fetch gzip compressed results
  • Works with Python 2.7.x and 3.x
  • Enable/disable color output (default: colorful)
  • Enable/disable debug logs (default: disabled)
  • Manpage for quick reference
  • Fast and clean (no ads or clutter)
  • Minimal dependencies
  • Open source and free

Installation

googler requires Python 2.7.x or Python 3.x to work.

  1. If you have git installed (the steps are tested on Ubuntu 14.04.3 x64_64):
$ git clone https://github.com/jarun/googler/  
$ cd googler  
$ sudo make install

To remove, run:

$ sudo make uninstall
  1. If you do not have git installed:
    Download the latest stable release or development version source code. Extract, cd into the directory and run:
$ sudo make install

If you do not want to install, googler is standalone:

$ chmod +x googler
$ ./googler ...
  1. googler is also available on AUR and Fossies.

Usage

$ googler
Usage: googler [OPTIONS] KEYWORDS...
Performs a Google search and prints the results to stdout.

Options
    -s N     start at the Nth result
    -n N     show N results (default 10)
    -N       show results from news section
    -c SERV  country-specific search (Ref: https://en.wikipedia.org/wiki/List_of_Google_domains)
             Added TLDs: ar, au, be, br, ca, ch, cz, de,
             es, fi, fr, id, in, it, jp, kr, mx, nl, ph,
             pl, pt, ro, ru, se, tw, ua, uk
    -l LANG  display in language LANG, such as fi for Finnish
    -C       disable color output
    -j       open the first result in a web browser
    -t dN    time limit search [h5 (5 hrs), d5 (5 days), w5 (5 weeks), m5 (5 months), y5 (5 years)]
    -d       enable debugging

Prompt Keys
    g terms  initiate a new search for 'terms' with original options
    n, p     fetch next or previous set of search results
    1-N      open the Nth result index in browser
    Enter    exit googler (same behaviour for an empty search)
    *        any other string initiates a new search with original options

Configuration file

googler doesn't have any! This is to retain the speed of the utlity and avoid OS-specific differences. Users can enjoy the advantage of config files using aliases. There's no need to memorize options.

For example, the following alias set in ~/.bashrc:

alias g='googler -n 7 -c ru -l ru'

fetches 7 results from the Google Russia server, with preference towards results in Russian.

The alias serves both the purposes of using config files:

  • persistent settings: when the user invokes g, it expands to the preferred settings everytime.
  • override settings: thanks to the way Python getopt() works, googler is written so that the settings in alias are completely overridden by any options passed from cli. So when the same user runs:
    $ g -l de -c de -n 12 hello world
    12 results are returned from the Google Germany server, with preference towards results in German.

Windows users can refer the following discussion on how to use aliases on Windows: http://stackoverflow.com/questions/20530996/aliases-in-windows-command-prompt

Examples

  1. Google hello world:
$ googler hello world
  1. To fetch 15 results updated within last 14 months, starting from the 3rd result for the string cmdline utility in site tuxdiary.com, run:
$ googler -n 15 -s 3 -t m14 cmdline utility site:tuxdiary.com
  1. Read recent news on gadgets:
$ googler -N gadgets
  1. Fetch results on IPL cricket from Google India server in English:
$ googler -c in -l en IPL cricket
  1. Search quoted text e.g. it's a "beautiful world" in spring:
$ googler it\'s a \"beautiful world\" in spring
  1. Search for a specific file type:
$ googler instrumental filetype:mp3
  1. I'm feeling lucky search:
$ googler -j leather jackets
  1. Website specific search alias:
alias t='googler -n 7 site:tuxdiary.com'
  1. Alias to find meanings of words (note: the first result in Google is not a link):
alias define='googler -n 2 define'
  1. Look up n, p, g co or a number at navigation prompt:
    As the navigation prompt recognizes n, p, g keywords or numbers as keys, they can't be searched directly without the g key. To search them -
Enter 'n', 'p', 'g keywords', or result number to continue: g n
Enter 'n', 'p', 'g keywords', or result number to continue: g g keywords
Enter 'n', 'p', 'g keywords', or result number to continue: g 1984

Note that Google ignores searches for negative numbers (e.g. -1984). 11. Input and output redirection:

$ googler -C hello world < input > output

Note that -C is required to avoid printing control characters. 2>&1 would error as the console geometry is calculated from stderr. 12. Piping googler output:

$ googler -C hello world | tee output

Developers

Copyright (C) 2008 Henri Hakkinen

Modified (2015) by Arun Prakash Jana

Notes

  1. Initially I raised a pull request but I could see that the last change was made 7 years earlier. In addition, there is no GitHub activity from the original author Henri Hakkinen in past year. I have created this independent repo for the project with the name googler. Would love to push the changes back to original repo if the author contacts. I retained the original copyright information.
  2. Google provides a search API which returns the results in JSON format. However, as per my understanding from the official docs, the API issues the queries against an existing instance of a custom search engine and is limited by 100 search queries per day for free. In addition, I have reservations in paying if they ever change their plan or restrict the API in other ways. So I refrained from coupling with Google plans & policies or exposing my trackable personal custom search API key and identifier for the public. I retained the browser-way of doing it by fetching html, which is a open and free specification.

About

Google from the command-line

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 84.9%
  • Roff 11.3%
  • Makefile 3.8%