Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
web-search plugin
-----------------
This plugin allow aliases for searching from terminal with some popular web search engines.
This plugin allows aliases for searching from terminal with some popular web search engines.

## Installation
## Installation

```sh
git clone https://github.com/sinetoami/web-search.git "$ZSH_CUSTOM/plugins/web-search"
Expand All @@ -28,6 +28,7 @@ The results are the same for both ways.
| alias | engine |
| --- | --- |
| `ddg` | `https://www.duckduckgo.com/?q=` |
| `brave` | `https://www.search.brave.com/?q=` |
| `google` | `https://www.google.com/search?q=` |
| `yahoo` | `https://search.yahoo.com/search?p=` |
| `github` | `https://github.com/search?q=` |
Expand Down
6 changes: 4 additions & 2 deletions web_search.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function web_search() {
[[ "$OSTYPE" = linux* ]] && open_cmd='xdg-open'
[[ "$OSTYPE" = darwin* ]] && open_cmd='open'

pattern='(google|duckduckgo|bing|yahoo|github|youtube)'
pattern='(google|duckduckgo|bing|yahoo|github|youtube|brave)'

# check whether the search engine is supported
if [[ $1 =~ pattern ]];
Expand All @@ -17,7 +17,7 @@ function web_search() {
fi

local url
[[ "$1" == 'yahoo' ]] && url="https://search.yahoo.com" || url="https://www.$1.com"
[[ "$1" == 'yahoo' || "$1" == 'brave' ]] && url="https://search.$1.com" || url="https://www.$1.com"

# no keyword provided, simply open the search engine homepage
if [[ $# -le 1 ]]; then
Expand All @@ -26,6 +26,7 @@ function web_search() {
fi

typeset -A search_syntax=(
brave "/search?q="
google "/search?q="
bing "/search?q="
github "/search?q="
Expand All @@ -46,6 +47,7 @@ function web_search() {
nohup $open_cmd "$url" &> /dev/null
}

alias brave='web_search brave'
alias bing='web_search bing'
alias google='web_search google'
alias yahoo='web_search yahoo'
Expand Down