#!/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=" ["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://15five.15five.com/admin/dj/company/company/?q=" ["ffsamlconf"]="https://15five.15five.com/admin/dj/saml2/saml2config/?q=" ) # List for rofi gen_list() { for i in "${!URLS[@]}"; do echo "$i" done } urlencode() { # urlencode 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") vimb $URL else exit fi else exit fi } main exit 0