hotchoco7 / google-cli

Google from the cmdline

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

google-cli

Screenshot

google-cli is a command line 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.

google-cli is GPLv3 licensed. It doesn't have any affiliation to Google in any way.

If you find google-cli 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
  • Initiate a new search with original options (in a single instance)
  • 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
  • UTF-8 request and response
  • 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

google-cli 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/google-cli/  
$ cd google-cli  
$ 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. google-cli is also available on AUR and Fossies.

Usage

Usage: googler [OPTIONS] KEYWORDS...
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

Keys
    g terms  enter 'g' followed by keywords to initiate a new search (with original options)
    n, p     enter 'n' or 'p' to navigate forward or backward
    1-N      enter a number to open that result in browser
             any other input exits googler

Configuration file

google-cli 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, google-cli 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. On the fly help (usage details):
$ googler
  1. 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 google-cli output:

$ googler -C hello world | tee output

Developers

Copyright (C) 2008 Henri Hakkinen

Modified (2015) by Arun Prakash Jana <engineerarun@gmail.com>

Note

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: https://github.com/henux ) in past year. I have created this independent repo for the project with the name google-cli. Would love to push the changes back to original repo if the author contacts. I retained the original copyright information.

About

Google from the cmdline

License:GNU General Public License v3.0


Languages

Language:Python 83.9%Language:Groff 11.9%Language:Makefile 4.2%