mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-27 00:00:08 +00:00
feat(web-search): add reddit engine 2.0
This commit is contained in:
parent
61bacd95b2
commit
f85e1bce67
1 changed files with 45 additions and 2 deletions
|
@ -32,7 +32,6 @@ function web_search() {
|
|||
packagist "https://packagist.org/?query="
|
||||
gopkg "https://pkg.go.dev/search?m=package&q="
|
||||
chatgpt "https://chatgpt.com/?q="
|
||||
reddit "https://www.reddit.com/search/?q="
|
||||
)
|
||||
|
||||
# check whether the search engine is supported
|
||||
|
@ -60,6 +59,50 @@ function web_search() {
|
|||
open_command "$url"
|
||||
}
|
||||
|
||||
# example usage: reddit swaywm (search all subreddits for swaywm)
|
||||
# example usage: reddit --sr unixporn swaywm (search only unixporn subreddit for swaywm) -> https://www.reddit.com/r/unixporn/search?q=swaywm
|
||||
|
||||
function reddit_search() {
|
||||
emulate -L zsh
|
||||
local url="https://www.reddit.com"
|
||||
local query=""
|
||||
local subreddit=""
|
||||
|
||||
# if the user pass "--sr <subreddit name>" as first argument
|
||||
# then the second argument is the subreddit name
|
||||
if [[ "$1" == "--sr" ]]; then
|
||||
subreddit="$2"
|
||||
query="${@[3,-1]}"
|
||||
else
|
||||
query="${@[1,-1]}"
|
||||
fi
|
||||
|
||||
# if query is empty, remove the search query
|
||||
if [[ -z "$query" ]]; then
|
||||
query=""
|
||||
fi
|
||||
|
||||
# if subreddit is empty, search all subreddits
|
||||
# but if query is empty, remove the search query
|
||||
if [[ -z "$subreddit" ]]; then
|
||||
if [[ -z "$query" ]]; then
|
||||
url="$url"
|
||||
else
|
||||
url="$url/search?q=$(omz_urlencode -P $query)"
|
||||
fi
|
||||
|
||||
else
|
||||
# if subreddit is not empty, search only that subreddit
|
||||
if [[ -z "$query" ]]; then
|
||||
url="$url/r/$subreddit"
|
||||
else
|
||||
url="$url/r/$subreddit/search?q=$(omz_urlencode -P $query)"
|
||||
fi
|
||||
fi
|
||||
|
||||
open_command "$url"
|
||||
}
|
||||
|
||||
|
||||
alias bing='web_search bing'
|
||||
alias brs='web_search brave'
|
||||
|
@ -86,7 +129,7 @@ alias npmpkg='web_search npmpkg'
|
|||
alias packagist='web_search packagist'
|
||||
alias gopkg='web_search gopkg'
|
||||
alias chatgpt='web_search chatgpt'
|
||||
alias reddit='web_search reddit'
|
||||
alias reddit='reddit_search'
|
||||
|
||||
#add your own !bang searches here
|
||||
alias wiki='web_search duckduckgo \!w'
|
||||
|
|
Loading…
Reference in a new issue