Skip to content

dkuryakin/googler

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

googler

AUR Homebrew Build Status

Asciicast

googler is a power tool to Google (Web & News) and Google Site Search from the terminal. It shows the title, URL and text context for each result, which can be directly opened in a browser from the terminal. Results are fetched in pages (with page navigation). Supports sequential searches in a single googler instance.

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

Got some suggestions? gitter chat with us.

Find googler useful? If you would like to donate, visit the Donate Button page.

Table of contents

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
  • Search any website using Google (like Google Site Search)
  • Reconnect on new search even if connection is closed due to inactivity
  • Disable automatic spelling correction and search exact keywords (default: enabled)
  • 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
  • Supports both long and short program options
  • Shell completion scripts for bash, zsh and fish
  • Country/domain specific search (28 top-level domains supported, default: .com)
  • Supports Google search keywords like filetype:mime, site:somesite.com etc.
  • 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.3.x or later
  • Enable/disable colour output (default: colourful)
  • 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 to work. Officially supported Python versions are 2.7 and 3.3 or later (only the latest patch release of each minor version is supported).

Installing from this repository

To download this repository, you may either clone via git:

$ git clone https://github.com/jarun/googler/

or download a source code archive: the latest stable release or the development version.

Installing to default or custom location

Run

$ sudo make install

to install to /usr/local. To install to a different prefix, run

$ PREFIX=/path/to/prefix make install

You may need to prepend sudo if the prefix is only writable by root.

To remove googler and associated docs, run

$ sudo make uninstall

If you installed to a different prefix, you'll need to specify the same PREFIX as when you ran make install.

Running as a standalone utility

googler is a standalone executable. From the containing directory:

$ ./googler

Shell completion

Shell completion scripts for Bash, Fish and Zsh can be found in respective subdirectories of auto-completion/. Please refer to your shell's manual for installation instructions.

Installing with a package manager

googler is also available on

Usage

Cmdline options

usage: googler [-s N] [-n N] [-N] [-c TLD] [-l LANG] [-x] [-C] [-j] [-t dN]
               [-w SITE] [-d]
               KEYWORD [KEYWORD ...]

Google from the command-line.

positional arguments:
  KEYWORD               search keywords

optional arguments:
  -s N, --start N       start at the Nth result
  -n N, --count N       show N results (default 10)
  -N, --news            show results from news section
  -c TLD, --tld TLD     country-specific search with top-level domain .TLD,
                        e.g., 'in' for India (refer
                        https://en.wikipedia.org/wiki/List_of_Google_domains
                        for a full list of TLDs)
  -l LANG, --lang LANG  display in language LANG
  -x, --exact           disable automatic spelling correction
  -C, --nocolor         disable color output
  -j, --first, --lucky  open the first result in a web browser
  -t dN, --time dN      time limit search [h5 (5 hrs), d5 (5 days), w5 (5
                        weeks), m5 (5 months), y5 (5 years)]
  -w SITE, --site SITE  search a site using Google
  -d, --debug           enable debugging

omniprompt keys:
  g keywords            initiate a new Google search for 'keywords' with original options
  n, p                  fetch next or previous set of search results
  1-N                   open the Nth result index in browser
  q, Enter              exit googler (same behaviour for an empty search)
  *                     any other string initiates a new search with original options
  ?                     show omniprompt help

Configuration file

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

For example, the following alias for bash/zsh/ksh/etc.

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.
  • 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 to this discussion on how to use aliases on Windows.

Examples

  1. Google hello world:

     $ googler hello world
    
  2. Fetch 15 results updated within last 14 months, starting from the 3rd result for the string cmdline utility in site tuxdiary.com:

     $ googler -n 15 -s 3 -t m14 -w tuxdiary.com cmdline utility
    
  3. Read recent news on gadgets:

     $ googler -N gadgets
    
  4. Fetch results on IPL cricket from Google India server in English:

     $ googler -c in -l en IPL cricket
    
  5. Search quoted text e.g. it's a "beautiful world" in spring:

     $ googler it\'s a \"beautiful world\" in spring
    
  6. Search for a specific file type:

     $ googler instrumental filetype:mp3
    
  7. Disable automatic spelling correction, e.g. fetch results for googler instead of google:

     $ googler -x googler
    
  8. I'm feeling lucky search:

     $ googler -j leather jackets
    
  9. Website specific search:

     $ googler -w tuxdiary.com hello world
    

Site specific search continues at omniprompt. Use the g key to run a regular Google search. 10. Alias to find definitions of words:

    alias define='googler -n 2 define'
  1. Look up n, p, q, g keywords or a number at the omniprompt: As the omniprompt recognizes n, p, q, g or numbers as commands, you need to prefix them with g, e.g.,

    g n
    g g keywords
    g 1984
    
  2. Input and output redirection:

    $ googler -C hello world < input > output
    

    Note that -C is required to avoid printing control characters (for colored output).

  3. Pipe output:

    $ googler -C hello world | tee output
    
  4. More help:

    $ googler
    $ man googler
    

Troubleshooting

  1. In some instances googler may show fewer number of results than you expect, e.g., if you fetch a single result (-n 1) it may not show any results. The reason is Google shows some Google service (e.g. Youtube) results, map locations etc. depending on your geographical data, which googler tries to omit. In some cases Google (the web-service) doesn't show exactly 10 results (default) on a search. We chose to omit these results as far as possible. While this can be fixed, it would need more processing (and more time). You can just navigate forward to fetch the next set of results.

Developers

  1. Copyright (C) 2008 Henri Hakkinen
  2. Resurrected and maintained (2015 -) by Arun Prakash Jana
  3. Zhiming Wang

Special thanks to jeremija, shaggytwodope and Narrat for their contributions and efforts in spreading googler.

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. 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 70.5%
  • Shell 16.2%
  • Roff 11.5%
  • Makefile 1.8%