2017-12-05 22:39:10 -08:00
|
|
|
#!/usr/bin/env zsh
|
|
|
|
|
2018-01-23 21:56:01 -08:00
|
|
|
# Performs an online search. Uses the last used provider, otherwise prompts for
|
2018-03-23 12:29:50 -07:00
|
|
|
# one with skim.
|
2018-01-23 21:56:01 -08:00
|
|
|
|
|
|
|
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')
|
|
|
|
|
2018-03-23 12:29:50 -07:00
|
|
|
pick=$(printf "%s\n" "${(@k)providers}" | sk --query="$provider" --prompt='provider > ' -1 -0)
|
2018-01-23 21:56:01 -08:00
|
|
|
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
|
2017-12-05 22:39:10 -08:00
|
|
|
fi
|
|
|
|
|
2018-01-23 21:56:01 -08:00
|
|
|
url=$(printf "${providers[$pick]}\n" $(uri<<<"$query"))
|
2017-12-05 22:39:10 -08:00
|
|
|
|
2018-01-23 21:56:01 -08:00
|
|
|
echo "Opening $url"
|
|
|
|
open $url
|