Skip to content

Commit

Permalink
frontend-search: add duckduckgo as an option for fallback search (#7973)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackbrown authored and mcornella committed Jul 31, 2019
1 parent 59c1ec8 commit 6d2221e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
4 changes: 4 additions & 0 deletions plugins/frontend-search/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ Available search contexts are:

If you want to have another context, open an Issue and tell us!

## Fallback search behaviour

The plugin will use Google as a fallback if the docs site for a search context does not have a search function. You can set the fallback search engine to DuckDuckGo by setting `FRONTEND_SEARCH_FALLBACK='duckduckgo'` in your `~/.zshrc` file before Oh My Zsh is sourced.

## Author

**Wilson Mendes (willmendesneto)**
Expand Down
31 changes: 21 additions & 10 deletions plugins/frontend-search/frontend-search.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,51 @@ alias typescript='frontend typescript'
alias unheap='frontend unheap'
alias vuejs='frontend vuejs'

function _frontend_fallback() {
local url
if [[ "$FRONTEND_SEARCH_FALLBACK" == duckduckgo ]]; then
url="https://duckduckgo.com/?sites=$1&q="
else
url="https://google.com/search?as_sitesearch=$1&as_q="
fi

echo "$url"
}

function frontend() {
emulate -L zsh

# define search context URLS
typeset -A urls
urls=(
angular 'https://angular.io/?search='
angularjs 'https://google.com/search?as_sitesearch=angularjs.org&as_q='
bem 'https://google.com/search?as_sitesearch=bem.info&as_q='
angularjs $(_frontend_fallback 'angularjs.org')
bem $(_frontend_fallback 'bem.info')
bootsnipp 'https://bootsnipp.com/search?q='
bundlephobia 'https://bundlephobia.com/result?p='
caniuse 'https://caniuse.com/#search='
codepen 'https://codepen.io/search?q='
compassdoc 'http://compass-style.org/search?q='
cssflow 'http://www.cssflow.com/search?q='
dartlang 'https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart:'
emberjs 'https://www.google.com/search?as_sitesearch=emberjs.com/&as_q='
flowtype 'https://google.com/search?as_sitesearch=flow.org/en/docs/&as_q='
emberjs $(_frontend_fallback 'emberjs.com/')
flowtype $(_frontend_fallback 'flow.org/en/docs/')
fontello 'http://fontello.com/#search='
github 'https://github.com/search?q='
html5please 'https://html5please.com/#'
jestjs 'https://www.google.com/search?as_sitesearch=jestjs.io&as_q='
jestjs $(_frontend_fallback 'jestjs.io')
jquery 'https://api.jquery.com/?s='
lodash 'https://devdocs.io/lodash/index#'
mdn 'https://developer.mozilla.org/search?q='
nodejs 'https://www.google.com/search?as_sitesearch=nodejs.org/en/docs/&as_q='
nodejs $(_frontend_fallback 'nodejs.org/en/docs/')
npmjs 'https://www.npmjs.com/search?q='
qunit 'https://api.qunitjs.com/?s='
reactjs 'https://google.com/search?as_sitesearch=facebook.github.io/react&as_q='
smacss 'https://google.com/search?as_sitesearch=smacss.com&as_q='
reactjs $(_frontend_fallback 'reactjs.org/')
smacss $(_frontend_fallback 'smacss.com')
stackoverflow 'https://stackoverflow.com/search?q='
typescript 'https://google.com/search?as_sitesearch=www.typescriptlang.org/docs&as_q='
typescript $(_frontend_fallback 'www.typescriptlang.org/docs')
unheap 'http://www.unheap.com/?s='
vuejs 'https://www.google.com/search?as_sitesearch=vuejs.org&as_q='
vuejs $(_frontend_fallback 'vuejs.org')
)

# show help for command list
Expand Down

0 comments on commit 6d2221e

Please sign in to comment.