summaryrefslogtreecommitdiff
path: root/plugins/frontend-search
diff options
context:
space:
mode:
authorTuowen Zhao <ztuowen@gmail.com>2023-12-09 13:20:13 -0800
committerTuowen Zhao <ztuowen@gmail.com>2023-12-09 13:20:13 -0800
commit7e951c254e779ff0620537cf43ca69dd878387b4 (patch)
treecb042e695bb3e11ed0483fad1af8a5b4f1bfc8d8 /plugins/frontend-search
parent4d908094fdc2a0c0e9a0a072eba213fab7adef43 (diff)
parent48ccc7b36de8efb2bd7beb9bd6e0a6f6fe03b95d (diff)
downloadzsh-7e951c254e779ff0620537cf43ca69dd878387b4.tar.gz
zsh-7e951c254e779ff0620537cf43ca69dd878387b4.tar.bz2
zsh-7e951c254e779ff0620537cf43ca69dd878387b4.zip
Merge remote-tracking branch 'github/master'
Diffstat (limited to 'plugins/frontend-search')
-rw-r--r--plugins/frontend-search/README.md12
-rw-r--r--plugins/frontend-search/frontend-search.plugin.zsh20
2 files changed, 25 insertions, 7 deletions
diff --git a/plugins/frontend-search/README.md b/plugins/frontend-search/README.md
index 050058931..920795060 100644
--- a/plugins/frontend-search/README.md
+++ b/plugins/frontend-search/README.md
@@ -60,12 +60,22 @@ Available search contexts are:
| typescript | `https://google.com/search?as_sitesearch=www.typescriptlang.org/docs&as_q=` |
| unheap | `http://www.unheap.com/?s=` |
| vuejs | `https://www.google.com/search?as_sitesearch=vuejs.org&as_q=` |
+| nextjs | `https://www.google.com/search?as_sitesearch=nextjs.org&as_q=` |
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.
+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.
+
+## DuckDuckGo Lucky Search
+
+Enable DuckDuckGo's "ducky" (lucky) search feature to automatically access the top search result. This feature
+is optimized for DuckDuckGo, as Google redirects to an intermediate page. The FRONTEND_SEARCH_FALLBACK_LUCKY
+environment variable triggers the use of DuckDuckGo's lucky search, rendering the FRONTEND_SEARCH_FALLBACK
+setting unnecessary in this context.
## Author
diff --git a/plugins/frontend-search/frontend-search.plugin.zsh b/plugins/frontend-search/frontend-search.plugin.zsh
index b9e2fe95d..c96596eb9 100644
--- a/plugins/frontend-search/frontend-search.plugin.zsh
+++ b/plugins/frontend-search/frontend-search.plugin.zsh
@@ -27,12 +27,19 @@ alias stackoverflow='frontend stackoverflow'
alias typescript='frontend typescript'
alias unheap='frontend unheap'
alias vuejs='frontend vuejs'
+alias nextjs='frontend nextjs'
function _frontend_fallback() {
- case "$FRONTEND_SEARCH_FALLBACK" in
- duckduckgo) echo "https://duckduckgo.com/?sites=$1&q=" ;;
- *) echo "https://google.com/search?as_sitesearch=$1&as_q=" ;;
- esac
+ if [[ "$FRONTEND_SEARCH_FALLBACK_LUCKY" == "true" ]]; then
+ case true in
+ *) echo "https://duckduckgo.com/?q=!ducky+site%3A$1+" ;;
+ esac
+ else
+ case "$FRONTEND_SEARCH_FALLBACK" in
+ duckduckgo) echo "https://duckduckgo.com/?sites=$1&q=" ;;
+ *) echo "https://google.com/search?as_sitesearch=$1&as_q=" ;;
+ esac
+ fi
}
function frontend() {
@@ -70,6 +77,7 @@ function frontend() {
typescript $(_frontend_fallback 'www.typescriptlang.org/docs')
unheap 'http://www.unheap.com/?s='
vuejs $(_frontend_fallback 'vuejs.org')
+ nextjs $(_frontend_fallback 'nextjs.org')
)
# show help for command list
@@ -81,7 +89,7 @@ function frontend() {
print -P ""
print -P " angular, angularjs, bem, bootsnipp, caniuse, codepen, compassdoc, cssflow, packagephobia"
print -P " dartlang, emberjs, fontello, flowtype, github, html5please, jestjs, jquery, lodash,"
- print -P " mdn, npmjs, nodejs, qunit, reactjs, smacss, stackoverflow, unheap, vuejs, bundlephobia"
+ print -P " mdn, npmjs, nodejs, qunit, reactjs, smacss, stackoverflow, unheap, vuejs, bundlephobia, nextjs"
print -P ""
print -P "For example: frontend npmjs mocha (or just: npmjs mocha)."
print -P ""
@@ -96,7 +104,7 @@ function frontend() {
echo ""
echo " angular, angularjs, bem, bootsnipp, caniuse, codepen, compassdoc, cssflow, packagephobia"
echo " dartlang, emberjs, fontello, github, html5please, jest, jquery, lodash,"
- echo " mdn, npmjs, nodejs, qunit, reactjs, smacss, stackoverflow, unheap, vuejs, bundlephobia"
+ echo " mdn, npmjs, nodejs, qunit, reactjs, smacss, stackoverflow, unheap, vuejs, bundlephobia, nextjs"
echo ""
return 1
fi