summaryrefslogtreecommitdiff
path: root/plugins/frontend-search
diff options
context:
space:
mode:
authorJack Brown <jackbrown@users.noreply.github.com>2019-07-31 17:45:54 +1000
committerMarc Cornellà <marc.cornella@live.com>2019-07-31 09:45:54 +0200
commit6d2221e697ea4a2445202b1c32283610f84585ef (patch)
tree9057987aa864ecec7a174017b342d64660d6c0b6 /plugins/frontend-search
parent59c1ec80aa9b018db34078e69a27e57aea5ad761 (diff)
downloadzsh-6d2221e697ea4a2445202b1c32283610f84585ef.tar.gz
zsh-6d2221e697ea4a2445202b1c32283610f84585ef.tar.bz2
zsh-6d2221e697ea4a2445202b1c32283610f84585ef.zip
frontend-search: add duckduckgo as an option for fallback search (#7973)
Diffstat (limited to 'plugins/frontend-search')
-rw-r--r--plugins/frontend-search/README.md4
-rw-r--r--plugins/frontend-search/frontend-search.plugin.zsh31
2 files changed, 25 insertions, 10 deletions
diff --git a/plugins/frontend-search/README.md b/plugins/frontend-search/README.md
index bf76902fd..ddcb3d72b 100644
--- a/plugins/frontend-search/README.md
+++ b/plugins/frontend-search/README.md
@@ -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)**
diff --git a/plugins/frontend-search/frontend-search.plugin.zsh b/plugins/frontend-search/frontend-search.plugin.zsh
index 87243be13..ed19280c4 100644
--- a/plugins/frontend-search/frontend-search.plugin.zsh
+++ b/plugins/frontend-search/frontend-search.plugin.zsh
@@ -27,6 +27,17 @@ 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
@@ -34,8 +45,8 @@ function frontend() {
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='
@@ -43,24 +54,24 @@ function frontend() {
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