diff options
Diffstat (limited to 'plugins/web-search')
-rw-r--r-- | plugins/web-search/README.md | 29 | ||||
-rw-r--r-- | plugins/web-search/web-search.plugin.zsh | 23 |
2 files changed, 51 insertions, 1 deletions
diff --git a/plugins/web-search/README.md b/plugins/web-search/README.md index d790d944d..da90f90a0 100644 --- a/plugins/web-search/README.md +++ b/plugins/web-search/README.md @@ -37,6 +37,11 @@ Available search contexts are: | `ecosia` | `https://www.ecosia.org/search?q=` | | `goodreads` | `https://www.goodreads.com/search?q=` | | `qwant` | `https://www.qwant.com/?q=` | +| `givero` | `https://www.givero.com/search?q=` | +| `stackoverflow` | `https://stackoverflow.com/search?q=` | +| `wolframalpha` | `https://wolframalpha.com/input?i=` | +| `archive` | `https://web.archive.org/web/*/` | +| `scholar` | `https://scholar.google.com/scholar?q=` | Also there are aliases for bang-searching DuckDuckGo: @@ -48,3 +53,27 @@ Also there are aliases for bang-searching DuckDuckGo: | `map` | `!m` | | `image` | `!i` | | `ducky` | `!` | + +### Custom search engines + +If you want to add other search contexts to the plugin, you can use the +`$ZSH_WEB_SEARCH_ENGINES` variable. Set it before Oh My Zsh is sourced, +with the following format: + +```zsh +ZSH_WEB_SEARCH_ENGINES=( + <context> <URL> + <context> <URL> +) +``` + +where `<context>` is the name of the search context, and `<URL>` a URL of +the same type as the search contexts above. For example, to add `reddit`, +you'd do: + +```zsh +ZSH_WEB_SEARCH_ENGINES=(reddit "https://www.reddit.com/search/?q=") +``` + +These custom search engines will also be turned to aliases, so you can +both do `web_search reddit <query>` or `reddit <query>`. diff --git a/plugins/web-search/web-search.plugin.zsh b/plugins/web-search/web-search.plugin.zsh index 863384223..0a2b8809e 100644 --- a/plugins/web-search/web-search.plugin.zsh +++ b/plugins/web-search/web-search.plugin.zsh @@ -6,6 +6,7 @@ function web_search() { # define search engine URLS typeset -A urls urls=( + $ZSH_WEB_SEARCH_ENGINES google "https://www.google.com/search?q=" bing "https://www.bing.com/search?q=" yahoo "https://search.yahoo.com/search?p=" @@ -17,11 +18,16 @@ function web_search() { ecosia "https://www.ecosia.org/search?q=" goodreads "https://www.goodreads.com/search?q=" qwant "https://www.qwant.com/?q=" + givero "https://www.givero.com/search?q=" + stackoverflow "https://stackoverflow.com/search?q=" + wolframalpha "https://www.wolframalpha.com/input/?i=" + archive "https://web.archive.org/web/*/" + scholar "https://scholar.google.com/scholar?q=" ) # check whether the search engine is supported if [[ -z "$urls[$1]" ]]; then - echo "Search engine $1 not supported." + echo "Search engine '$1' not supported." return 1 fi @@ -51,6 +57,11 @@ alias baidu='web_search baidu' alias ecosia='web_search ecosia' alias goodreads='web_search goodreads' alias qwant='web_search qwant' +alias givero='web_search givero' +alias stackoverflow='web_search stackoverflow' +alias wolframalpha='web_search wolframalpha' +alias archive='web_search archive' +alias scholar='web_search scholar' #add your own !bang searches here alias wiki='web_search duckduckgo \!w' @@ -59,3 +70,13 @@ alias youtube='web_search duckduckgo \!yt' alias map='web_search duckduckgo \!m' alias image='web_search duckduckgo \!i' alias ducky='web_search duckduckgo \!' + +# other search engine aliases +if [[ ${#ZSH_WEB_SEARCH_ENGINES} -gt 0 ]]; then + typeset -A engines + engines=($ZSH_WEB_SEARCH_ENGINES) + for key in ${(k)engines}; do + alias "$key"="web_search $key" + done + unset engines key +fi |