handy

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

rofi-web-search.sh (2073B)


      1 #!/usr/bin/env bash
      2 # rofi-scripts/web-search.sh at master ยท miroslavvidovic/rofi-scripts
      3 # https://github.com/miroslavvidovic/rofi-scripts/blob/master/web-search.sh
      4 
      5 
      6 
      7 
      8 # -----------------------------------------------------------------------------
      9 # Info:
     10 #   author:    Miroslav Vidovic
     11 #   file:      web-search.sh
     12 #   created:   24.02.2017.-08:59:54
     13 #   revision:  ---
     14 #   version:   1.0
     15 # -----------------------------------------------------------------------------
     16 # Requirements:
     17 #   rofi
     18 # Description:
     19 #   Use rofi to search the web.
     20 # Usage:
     21 #   web-search.sh
     22 # -----------------------------------------------------------------------------
     23 # Script:
     24 
     25 declare -A URLS
     26 
     27 URLS=(
     28   ["google"]="https://www.google.com/search?q="
     29   ["bing"]="https://www.bing.com/search?q="
     30   ["yahoo"]="https://search.yahoo.com/search?p="
     31   ["duckduckgo"]="https://www.duckduckgo.com/?q="
     32   ["yandex"]="https://yandex.ru/yandsearch?text="
     33   ["github"]="https://github.com/search?q="
     34   ["goodreads"]="https://www.goodreads.com/search?q="
     35   ["stackoverflow"]="http://stackoverflow.com/search?q="
     36   ["symbolhound"]="http://symbolhound.com/?q="
     37   ["searchcode"]="https://searchcode.com/?q="
     38   ["openhub"]="https://www.openhub.net/p?ref=homepage&query="
     39   ["superuser"]="http://superuser.com/search?q="
     40   ["askubuntu"]="http://askubuntu.com/search?q="
     41   ["imdb"]="http://www.imdb.com/find?ref_=nv_sr_fn&q="
     42   ["rottentomatoes"]="https://www.rottentomatoes.com/search/?search="
     43   ["piratebay"]="https://thepiratebay.org/search/"
     44   ["youtube"]="https://www.youtube.com/results?search_query="
     45   ["vimawesome"]="http://vimawesome.com/?q="
     46 )
     47 
     48 # List for rofi
     49 gen_list() {
     50     for i in "${!URLS[@]}"
     51     do
     52       echo "$i"
     53     done
     54 }
     55 
     56 main() {
     57   # Pass the list to rofi
     58   platform=$( (gen_list) | rofi -dmenu -matching fuzzy -only-match -location 0 -p "Search > " )
     59 
     60   query=$( (echo ) | rofi  -dmenu -matching fuzzy -location 0 -p "Query > " )
     61   if [[ -n "$query" ]]; then
     62     url=${URLS[$platform]}$query
     63     xdg-open "$url"
     64   else
     65     rofi -show -e "No query provided."
     66   fi
     67 }
     68 
     69 main
     70 
     71 exit 0