#!/usr/bin/env zsh # Performs an online search. Uses the last used provider, otherwise prompts for # one with skim. provider="$1"; shift query="$*" typeset -A providers providers+=('DuckDuckGo' 'https://duckduckgo.com/?q=%s') providers+=('DevDocs.io' 'http://devdocs.io/#q=%s') providers+=('Google search' 'https://google.com/search?q=%s') providers+=('Google images' 'https://google.com/images?q=%s') providers+=('Google maps' 'https://maps.google.com/maps?q=%s') providers+=('Project Gutenberg' 'http://www.gutenberg.org/ebooks/search/?query=%s') providers+=('StackOverflow' 'https://stackoverflow.com/search?q=%s') providers+=('Github' 'https://github.com/search?ref=simplesearch&q=%s') providers+=('Youtube' 'https://youtube.com/results?aq=f&oq=&search_query=%s') providers+=('Wolfram alpha' 'https://wolframalpha.com/input/?i=%s') providers+=('Wikipedia' 'https://wikipedia.org/search-redirect.php?language=en&go=Go&search=%s') pick=$(printf "%s\n" "${(@k)providers}" | sk --query="$provider" --prompt='provider > ' -1 -0) if [[ -z $pick ]]; then >&2 echo 'No provider selected. Aborting.' exit 1 elif [[ -z ${providers[$pick]} ]]; then >&2 echo 'No provider matched that query. Aborting.' exit 2 fi url=$(printf "${providers[$pick]}\n" $(uri<<<"$query")) echo "Opening $url" open $url