web-search.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/usr/bin/env bash
  2. # -----------------------------------------------------------------------------
  3. # Info:
  4. # author: Miroslav Vidovic
  5. # file: web-search.sh
  6. # created: 24.02.2017.-08:59:54
  7. # revision: ---
  8. # version: 1.0
  9. # -----------------------------------------------------------------------------
  10. # Requirements:
  11. # rofi
  12. # Description:
  13. # Use rofi to search the web.
  14. # Usage:
  15. # web-search.sh
  16. # -----------------------------------------------------------------------------
  17. # Script:
  18. declare -A URLS
  19. URLS=(
  20. ["search"]="https://search.unbl.ink/?q="
  21. ["google"]="https://www.google.com/search?q="
  22. ["ddg"]="https://www.duckduckgo.com/?q="
  23. ["amazon"]="https://www.amazon.com/s?k="
  24. ["github"]="https://github.com/search?q="
  25. ["goodreads"]="https://www.goodreads.com/search?q="
  26. ["stackoverflow"]="http://stackoverflow.com/search?q="
  27. ["symbolhound"]="http://symbolhound.com/?q="
  28. ["searchcode"]="https://searchcode.com/?q="
  29. ["imdb"]="http://www.imdb.com/find?ref_=nv_sr_fn&q="
  30. ["rottentomatoes"]="https://www.rottentomatoes.com/search/?search="
  31. ["invidous"]="https://invidio.us/search?q="
  32. ["vimawesome"]="http://vimawesome.com/?q="
  33. ["beer"]="https://www.beeradvocate.com/search/?qt=beer&q="
  34. ["jira"]="https://15five-dev.atlassian.net/plugins/servlet/mobile#issue/ENG-"
  35. ["books"]="https://b-ok.cc/s/?q="
  36. ["maps"]="https://www.openstreetmap.com/search?query="
  37. ["pirate"]="https://proxahoy.link/s/?q="
  38. )
  39. # List for rofi
  40. gen_list() {
  41. for i in "${!URLS[@]}"
  42. do
  43. echo "$i"
  44. done
  45. }
  46. main() {
  47. # Pass the list to rofi
  48. platform=$( (gen_list) | rofi -dmenu -matching fuzzy -no-custom -location 0 -p "Search > " )
  49. if [[ -n "$platform" ]]; then
  50. query=$( (echo ) | rofi -dmenu -matching fuzzy -location 0 -p "Query > " )
  51. if [[ -n "$query" ]]; then
  52. url=${URLS[$platform]}$query
  53. xdg-open "$url"
  54. else
  55. exit
  56. fi
  57. else
  58. exit
  59. fi
  60. }
  61. main
  62. exit 0