Quick Search for the Internet using the command line

Source: Internet
Author: User
Firefox has a function that is very useful, that is, inputting g and adding the keyword to search, you can automatically search on Google. This function is called quicksearch.

I want this feature to be available in the command line, so I wrote a bash script named search myself. You can directly call the text interface's browser search (such as w3m or Lynx) in the command line ).

The usage is as follows:
Search for keywords in Google:
$ Search g keyword [keyword]...

Search for keywords in Google blogsearch:
$ Search B keyword [keyword]...

Dictionary query:
$ Search D keyword

If you set alias (search will actually help you ):
Then the above three searches can be simplified
$ G keyword [keyword]...
$ B keyword [keyword]...
$ D keyword

The search engine can be customized, And the customization process is simple. It is no different from the setting of quicksearch in Firefox.

Install search in the/usr/bin directory:
$ Search install

Output the alias script to the standard output:
$ Search mkalias

Typical installation process:
$ Su
$ Search install; exit
$ Search mkalias >> ~ /. Bashrc; source ~ /. Bashrc

The source code is as follows :#! /Bin/sh

# Written by redguardtoo
Search_alias = (g r n wi c B D)
Search_url = ("http://www.google.com/search? Q = % S & Ie = UTF-8 & OE = UTF-8"
"Http://groups.google.com/groups? Q = % S & sourceid = opera & num = % I & Ie = UTF-8 & OE = UTF-8"
"Http://news.google.com/news? Q = % S & sourceid = opera & num = % I & Ie = UTF-8 & OE = UTF-8"
"Https://secure.wikimedia.org/wikipedia/en/wiki/Special:Search? Search = % s"
"Https://secure.wikimedia.org/wikipedia/zh/wiki/Special:Search? Search = % s"
"Http://blogsearch.google.com/blogsearch? Hl = en & Ie = UTF-8 & Q = % S & btng = SEARCH + blogs"
Http://www.m-w.com/dictionary/%s"
)
Browser_prog = w3m
Browser_option = "-o gbk-cookie"
Prog = 'basename $0'


# If [$ (whoami )! = 'Root']; then
# Echo "must be root to run $0"
# Exit 1;
# Fi

If [-Z $1]; then
Echo "Search version 0.0.1"
Echo "Usage: $ prog alias keyword"
Echo "$ prog install"
Echo "$ prog Uninstall"
Echo "$ prog mkalias"
Exit 1
Fi

If ["$1" = "Install"]; then
Echo "installing ..."
CP $0/usr/bin/$ prog
Exit 0
Fi

If ["$1" = "Uninstall"]; then
Echo "uninstalling ..."
Rm/usr/bin/$ prog
Exit 0
Fi

If ["$1" = "mkalias"]; then
For Sa in $ {search_alias [@]}; do
Echo alias $ SA = "/usr/bin/$ prog $ SA"
Done
Exit 0
Fi

Query_shortcut = $1
# Echo $ # debug
If [$ #-GT 1]; then
Shift
Query_para = $ *
# Echo $ query_para # debug
Fi

Count = 0
For Sa in $ {search_alias [@]}; do
If ["$ query_shortcut" = "$ SA"]; then
Query_url =$ {search_url [$ count]}
Query_url =$ {query_url // "% s"/"$ query_para "}
Query_url =$ {query_url // ""/"+ "}
# Echo $ query_url # debug
$ Browser_prog $ browser_option $ {query_url/"% s"/"$ query_para "}
Fi
Count = $ ($ count + 1 ))
Done

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.