12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- #!/usr/bin/env bash
- # -----------------------------------------------------------------------------
- # Info:
- # author: Miroslav Vidovic
- # file: web-search.sh
- # created: 24.02.2017.-08:59:54
- # revision: ---
- # version: 1.0
- # -----------------------------------------------------------------------------
- # Requirements:
- # rofi
- # Description:
- # Use rofi to search the web.
- # Usage:
- # web-search.sh
- # -----------------------------------------------------------------------------
- # Script:
- declare -A URLS
- # Default book search
- # https://b-ok.cc/s/?q="
- #
- URLS=(
- ["books"]="http://1lib.us/s/"
- ["amazon"]="https://www.amazon.com/s?k="
- ["stackoverflow"]="http://stackoverflow.com/search?q="
- ["hoogle"]="https://www.google.com/search?q="
- ["code"]="https://searchcode.com/?q="
- ["beer"]="https://www.beeradvocate.com/search/?qt=beer&q="
- ["jira"]="https://15five-dev.atlassian.net/browse/ENG-"
- ["booty"]="https://thepiratebay.zone/search/"
- ["search"]="https://search.unbl.ink/?q="
- ["ebay"]="https://www.ebay.com/sch/i.html?LH_BIN=1&_nkw="
- ["ffcompany"]="https://admin.cloud100.15five.com/admin/dj/company/company/"
- ["ffuser"]="https://admin.cloud100.15five.com/admin/dj/ff/user/?q="
- ["ffsamlconf"]="https://admin.cloud100.15five.com/admin/dj/saml2/saml2config/?q="
- ["mathdisc"]="https://github.com/centerofci/mathesar/discussions/"
- ["mathissue"]="https://github.com/centerofci/mathesar/issues/"
- ["metacritic"]="https://www.metacritic.com/search/all/"
- )
- # List for rofi
- gen_list() {
- for i in "${!URLS[@]}"; do
- echo "$i"
- done
- }
- urlencode() {
- # urlencode <string>
- local LANG=C
- local length="${#1}"
- for ((i = 0; i < length; i++)); do
- local c="${1:i:1}"
- case $c in
- [a-zA-Z0-9.~_-]) printf "$c" ;;
- *) printf '%%%02X' "'$c" ;;
- esac
- done
- }
- main() {
- # Pass the list to rofi
- platform=$( (gen_list) | rofi -dmenu -matching fuzzy -no-custom -location 0 -p "Search > ")
- if [[ -n "$platform" ]]; then
- query=$( (echo) | rofi -dmenu -matching fuzzy -location 0 -p "Query > ")
- if [[ -n "$query" ]]; then
- URL=${URLS[$platform]}$(urlencode "$query")
- if [[ $platform = 'ffcompany' ]]; then
- surf $URL
- elif [[ $platform = 'ffuser' ]]; then
- surf $URL
- elif [[ $platform = 'ffsamlconf' ]]; then
- surf $URL
- else
- qutebrowser --target window $URL
- fi
- else
- exit
- fi
- else
- exit
- fi
- }
- main
- exit 0
|