web-search.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. ["books"]="https://b-ok.cc/s/"
  24. ["amazon"]="https://www.amazon.com/s?k="
  25. ["stackoverflow"]="http://stackoverflow.com/search?q="
  26. ["hoogle"]="https://www.google.com/search?q="
  27. ["code"]="https://searchcode.com/?q="
  28. ["beer"]="https://www.beeradvocate.com/search/?qt=beer&q="
  29. ["jira"]="https://15five-dev.atlassian.net/plugins/servlet/mobile#issue/"
  30. ["booty"]="https://thepiratebay.zone/search/"
  31. ["search"]="https://search.unbl.ink/?q="
  32. ["guru"]="https://app.getguru.com/search?q="
  33. ["ebay"]="https://www.ebay.com/sch/i.html?LH_BIN=1&_nkw="
  34. ["ffcompany"]="https://admin.cloud100.15five.com/admin/dj/company/company/?q="
  35. ["ffuser"]="https://admin.cloud100.15five.com/admin/dj/ff/user/?q="
  36. ["ffsamlconf"]="https://admin.cloud100.15five.com/admin/dj/saml2/saml2config/?q="
  37. ["mathdisc"]="https://github.com/centerofci/mathesar/discussions/"
  38. ["mathissue"]="https://github.com/centerofci/mathesar/issues/"
  39. ["metacritic"]="https://www.metacritic.com/search/all/"
  40. )
  41. # List for rofi
  42. gen_list() {
  43. for i in "${!URLS[@]}"; do
  44. echo "$i"
  45. done
  46. }
  47. urlencode() {
  48. # urlencode <string>
  49. local LANG=C
  50. local length="${#1}"
  51. for ((i = 0; i < length; i++)); do
  52. local c="${1:i:1}"
  53. case $c in
  54. [a-zA-Z0-9.~_-]) printf "$c" ;;
  55. *) printf '%%%02X' "'$c" ;;
  56. esac
  57. done
  58. }
  59. main() {
  60. # Pass the list to rofi
  61. platform=$( (gen_list) | rofi -dmenu -matching fuzzy -no-custom -location 0 -p "Search > ")
  62. if [[ -n "$platform" ]]; then
  63. query=$( (echo) | rofi -dmenu -matching fuzzy -location 0 -p "Query > ")
  64. if [[ -n "$query" ]]; then
  65. URL=${URLS[$platform]}$(urlencode "$query")
  66. qutebrowser --target window $URL
  67. else
  68. exit
  69. fi
  70. else
  71. exit
  72. fi
  73. }
  74. main
  75. exit 0