Advertisement
v1ral_ITS

web-search

May 4th, 2019
1,048
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.08 KB | None | 0 0
  1. # web_search from terminal
  2.  
  3. function web_search() {
  4.   emulate -L zsh
  5.  
  6.   # define search engine URLS
  7.   typeset -A urls
  8.   urls=(
  9.     google      "https://www.google.com/search?q="
  10.     bing        "https://www.bing.com/search?q="
  11.     yahoo       "https://search.yahoo.com/search?p="
  12.     duckduckgo  "https://www.duckduckgo.com/?q="
  13.     startpage   "https://www.startpage.com/do/search?q="
  14.     yandex      "https://yandex.ru/yandsearch?text="
  15.     github      "https://github.com/search?q="
  16.     baidu       "https://www.baidu.com/s?wd="
  17.     ecosia      "https://www.ecosia.org/search?q="
  18.     goodreads   "https://www.goodreads.com/search?q="
  19.     qwant       "https://www.qwant.com/?q="
  20.     givero      "https://www.givero.com/search?q="
  21.     stackoverflow  "https://stackoverflow.com/search?q="
  22.   )
  23.  
  24.   # check whether the search engine is supported
  25.   if [[ -z "$urls[$1]" ]]; then
  26.     echo "Search engine $1 not supported."
  27.     return 1
  28.   fi
  29.  
  30.   # search or go to main page depending on number of arguments passed
  31.   if [[ $# -gt 1 ]]; then
  32.     # build search url:
  33.     # join arguments passed with '+', then append to search engine URL
  34.     url="${urls[$1]}${(j:+:)@[2,-1]}"
  35.   else
  36.     # build main page url:
  37.     # split by '/', then rejoin protocol (1) and domain (2) parts with '//'
  38.     url="${(j://:)${(s:/:)urls[$1]}[1,2]}"
  39.   fi
  40.  
  41.   open_command "$url"
  42. }
  43.  
  44.  
  45. alias bing='web_search bing'
  46. alias google='web_search google'
  47. alias yahoo='web_search yahoo'
  48. alias ddg='web_search duckduckgo'
  49. alias sp='web_search startpage'
  50. alias yandex='web_search yandex'
  51. alias github='web_search github'
  52. alias baidu='web_search baidu'
  53. alias ecosia='web_search ecosia'
  54. alias goodreads='web_search goodreads'
  55. alias qwant='web_search qwant'
  56. alias givero='web_search givero'
  57. alias stackoverflow='web_search stackoverflow'
  58.  
  59. #add your own !bang searches here
  60. alias wiki='web_search duckduckgo \!w'
  61. alias news='web_search duckduckgo \!n'
  62. alias youtube='web_search duckduckgo \!yt'
  63. alias map='web_search duckduckgo \!m'
  64. alias image='web_search duckduckgo \!i'
  65. alias ducky='web_search duckduckgo \!'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement