dm-search.sh 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/usr/bin/env bash
  2. #
  3. # Script name: dmenu-search.sh
  4. # Description: Search various search engines (inspired by surfraw).
  5. # Dependencies: dmenu and a web browser
  6. # GitLab: https://www.gitlab.com/dwt1/dmscripts
  7. # License: https://www.gitlab.com/dwt1/dmscripts/LICENSE
  8. # Contributors: Derek Taylor
  9. # Ali Furkan Yıldız
  10. # Defining our web browser.
  11. DMBROWSER="${BROWSER:-brave}"
  12. # An array of search engines. You can edit this list to add/remove
  13. # search engines. The format must be: "engine_name - url".
  14. # The url format must allow for the search keywords at the end of the url.
  15. # For example: https://www.amazon.com/s?k=XXXX searches Amazon for 'XXXX'.
  16. declare -a options=(
  17. "amazon - https://www.amazon.com/s?k="
  18. "archaur - https://aur.archlinux.org/packages/?O=0&K="
  19. "archpkg - https://archlinux.org/packages/?sort=&q="
  20. "archwiki - https://wiki.archlinux.org/index.php?search="
  21. "arxiv - https://arxiv.org/search/?searchtype=all&source=header&query="
  22. "bbcnews - https://www.bbc.co.uk/search?q="
  23. "bing - https://www.bing.com/search?q="
  24. "cliki - https://www.cliki.net/site/search?query="
  25. "cnn - https://www.cnn.com/search?q="
  26. "coinbase - https://www.coinbase.com/price?query="
  27. "debianpkg - https://packages.debian.org/search?suite=default&section=all&arch=any&searchon=names&keywords="
  28. "discogs - https://www.discogs.com/search/?&type=all&q="
  29. "duckduckgo - https://duckduckgo.com/?q="
  30. "ebay - https://www.ebay.com/sch/i.html?&_nkw="
  31. "github - https://github.com/search?q="
  32. "gitlab - https://gitlab.com/search?search="
  33. "google - https://www.google.com/search?q="
  34. "googleimages - https://www.google.com/search?hl=en&tbm=isch&q="
  35. "googlenews - https://news.google.com/search?q="
  36. "imdb - https://www.imdb.com/find?q="
  37. "lbry - https://lbry.tv/$/search?q="
  38. "odysee - https://odysee.com/$/search?q="
  39. "reddit - https://www.reddit.com/search/?q="
  40. "slashdot - https://slashdot.org/index2.pl?fhfilter="
  41. "socialblade - https://socialblade.com/youtube/user/"
  42. "sourceforge - https://sourceforge.net/directory/?q="
  43. "stack - https://stackoverflow.com/search?q="
  44. "startpage - https://www.startpage.com/do/dsearch?query="
  45. "stockquote - https://finance.yahoo.com/quote/"
  46. "thesaurus - https://www.thesaurus.com/misspelling?term="
  47. "translate - https://translate.google.com/?sl=auto&tl=en&text="
  48. "urban - https://www.urbandictionary.com/define.php?term="
  49. "wayback - https://web.archive.org/web/*/"
  50. "webster - https://www.merriam-webster.com/dictionary/"
  51. "wikipedia - https://en.wikipedia.org/wiki/"
  52. "wiktionary - https://en.wiktionary.org/wiki/"
  53. "wolfram - https://www.wolframalpha.com/input/?i="
  54. "youtube - https://www.youtube.com/results?search_query="
  55. "quit"
  56. )
  57. # Colors:
  58. # Materia Manjaro
  59. nf='#09dbc9'
  60. nb='#222b2e'
  61. sf='#dbdcd5'
  62. sb='#009185'
  63. fn='Ubuntu-16:normal'
  64. # Gruvbox
  65. # nf='#fea63c'
  66. # nb='#282828'
  67. # # sf='#dbdcd5'
  68. # sb='#d79921'
  69. # fn='Sarasa Mono SC Nerd-17:normal'
  70. # Picking a search engine.
  71. while [[ -z "$engine" ]]; do
  72. enginelist=$(printf '%s\n' "${options[@]}" | \
  73. dmenu -i -l 20 -nf ${nf} -nb ${nb} \
  74. -sf ${sf} -sb ${sb} \
  75. -fn ${fn} -p 'Choose search engine:') || exit
  76. engineurl=$(echo "$enginelist" | awk '{print $NF}')
  77. engine=$(echo "$enginelist" | awk '{print $1}')
  78. done
  79. # Searching the chosen engine.
  80. while [[ -z "$query" ]]; do
  81. query=$(echo "$engine" | \
  82. dmenu -i -l 1 -nf ${nf} -nb ${nb} \
  83. -sf ${sf} -sb ${sb} \
  84. -fn ${fn} -p 'Enter search query:') || exit
  85. done
  86. # Display search results in web browser
  87. $DMBROWSER "$engineurl""$query"