summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorMarc Cornellà <marc.cornella@live.com>2020-06-10 12:04:14 +0200
committerMarc Cornellà <marc.cornella@live.com>2020-06-10 12:04:14 +0200
commit60442dc47b9092375bb41a1f803b25389c834427 (patch)
tree0381520dc8e5cb0e0d75c462126817005d3c9ffc /plugins
parent3c777ebf1b24826363bea6bc29afa9ba038b10e8 (diff)
downloadzsh-60442dc47b9092375bb41a1f803b25389c834427.tar.gz
zsh-60442dc47b9092375bb41a1f803b25389c834427.tar.bz2
zsh-60442dc47b9092375bb41a1f803b25389c834427.zip
web-search: allow custom search engines
Diffstat (limited to 'plugins')
-rw-r--r--plugins/web-search/README.md24
-rw-r--r--plugins/web-search/web-search.plugin.zsh13
2 files changed, 36 insertions, 1 deletions
diff --git a/plugins/web-search/README.md b/plugins/web-search/README.md
index 81908fb94..ad5080a44 100644
--- a/plugins/web-search/README.md
+++ b/plugins/web-search/README.md
@@ -52,3 +52,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 326a30745..e8842d906 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="
@@ -25,7 +26,7 @@ function web_search() {
# 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
@@ -67,3 +68,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