Search the Internet with DMENU


Search the Internet with DMENU

As i showed in a previous post, with fzf, we can also use dmenu as a method to input text. It's not that difficult, but tricky yes. So, with this method, i built a BASH script, to search the Internet with the search engines i prefer, from everywhere i am at the desktop. No need to pull the terminal or even ALT-TAB to your browser. You can be at your text editor or reading an ebook and with just a key combination, initiate the script and search the Internet for something you read. Normally, you should, open the terminal, type a command or ALT-TAB to your browser, CTRL-L and then type what you want.

In dmenu you can write anything you want in the prompt and when you press SHIFT+RETURN, dmenu will return that string, instead of an option. This is a default behavior of dmenu no need to apply any patched on it. Check the script and you will get it. Make sure to insert your preferred search engines, browser, colors and font ;)

#!/usr/bin/bash

DMENU="dmenu -i -fn IBMPlexMonoMedium-14 -nb #282828 -sb #E6823A -sf black -p"
VERTLIST="-l 20"

engines=("Google"
"Skroutz"
"Yandex"
"Gibiru"
"Metager"
"Mojeek"
)

function encode() {
encoded_value=$(echo "$*" | sed -e 's/%/%25/g' -e 's/ /%20/g' -e 's/!/%21/g' -e 's/"/%22/g' -e 's/#/%23/g' -e 's/\$/%24/g' -e 's/\&/%26/g' -e 's/'\''/%27/g' -e 's/(/%28/g' -e 's/)/%29/g' -e 's/\*/%2a/g' -e 's/+/%2b/g' -e 's/,/%2c/g' -e 's/-/%2d/g' -e 's/\./%2e/g' -e 's/\//%2f/g' -e 's/:/%3a/g' -e 's/;/%3b/g' -e 's//%3e/g' -e 's/?/%3f/g' -e 's/@/%40/g' -e 's/\[/%5b/g' -e 's/\\/%5c/g' -e 's/\]/%5d/g' -e 's/\^/%5e/g' -e 's/_/%5f/g' -e 's/`/%60/g' -e 's/{/%7b/g' -e 's/|/%7c/g' -e 's/}/%7d/g' -e 's/~/%7e/g')
  echo "$encoded_value"
}

value="$(echo "Enter Search string and press Shift+Return" | $DMENU "Query:" )"
if [ -z "$value" ]; then exit; fi
sel="$(printf "%s\n" "${engines[@]}" | $DMENU "Search Engine:" -l 10)"

case "$sel" in
  "Google") url="https://www.google.com/search?q=";;
  "Gibiru") url="https://gibiru.com/results.html?q=";;
  "Metager") url="https://metager.org/meta/meta.ger3?eingabe=";;
  "Skroutz") url="https://www.skroutz.gr/search?keyphrase=";;
  "Mojeek") url="https://www.mojeek.com/search?q=";;
  "Yandex") url="https://yandex.ru/search/?text=";;
  *) exit;;
esac
encoded_value="$(encode $value)"
firefox ${url}${encoded_value}

Add a comment

Previous Next