web-search.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. # Default book search
  20. # https://b-ok.cc/s/?q="
  21. #
  22. URLS=(
  23. ["search"]="https://search.unbl.ink/?q="
  24. ["google"]="https://www.google.com/search?q="
  25. ["ddg"]="https://www.duckduckgo.com/?q="
  26. ["amazon"]="https://www.amazon.com/s?k="
  27. ["github"]="https://github.com/search?q="
  28. ["goodreads"]="https://www.goodreads.com/search?q="
  29. ["stackoverflow"]="http://stackoverflow.com/search?q="
  30. ["symbolhound"]="http://symbolhound.com/?q="
  31. ["searchcode"]="https://searchcode.com/?q="
  32. ["imdb"]="http://www.imdb.com/find?ref_=nv_sr_fn&q="
  33. ["rottentomatoes"]="https://www.rottentomatoes.com/search/?search="
  34. ["invidous"]="https://invidio.us/search?q="
  35. ["vimawesome"]="http://vimawesome.com/?q="
  36. ["beer"]="https://www.beeradvocate.com/search/?qt=beer&q="
  37. ["jira"]="https://15five-dev.atlassian.net/plugins/servlet/mobile#issue/ENG-"
  38. ["books"]="http://zlibraryexau2g3p.onion/s/"
  39. ["maps"]="https://www.openstreetmap.com/search?query="
  40. ["pirate"]="https://proxahoy.link/s/?q="
  41. )
  42. # List for rofi
  43. gen_list() {
  44. for i in "${!URLS[@]}"
  45. do
  46. echo "$i"
  47. done
  48. }
  49. main() {
  50. # Pass the list to rofi
  51. platform=$( (gen_list) | rofi -dmenu -matching fuzzy -no-custom -location 0 -p "Search > " )
  52. if [[ -n "$platform" ]]; then
  53. query=$( (echo ) | rofi -dmenu -matching fuzzy -location 0 -p "Query > " )
  54. if [[ -n "$query" ]]; then
  55. url=${URLS[$platform]}$query
  56. xdg-open "$url"
  57. else
  58. exit
  59. fi
  60. else
  61. exit
  62. fi
  63. }
  64. main
  65. exit 0