conf2/zsh/.oh-my-zsh/plugins/frontend-search/frontend-search.plugin.zsh

119 lines
4.4 KiB
Bash
Raw Normal View History

2019-10-24 19:09:05 +00:00
alias angular='frontend angular'
2019-01-12 15:47:23 +00:00
alias angularjs='frontend angularjs'
alias bem='frontend bem'
alias bootsnipp='frontend bootsnipp'
2019-10-24 19:09:05 +00:00
alias bundlephobia='frontend bundlephobia'
2019-01-12 15:47:23 +00:00
alias caniuse='frontend caniuse'
alias codepen='frontend codepen'
alias compassdoc='frontend compassdoc'
alias cssflow='frontend cssflow'
alias dartlang='frontend dartlang'
alias emberjs='frontend emberjs'
2019-10-24 19:09:05 +00:00
alias flowtype='frontend flowtype'
2019-01-12 15:47:23 +00:00
alias fontello='frontend fontello'
2019-10-24 19:09:05 +00:00
alias github='frontend github'
2019-01-12 15:47:23 +00:00
alias html5please='frontend html5please'
2019-10-24 19:09:05 +00:00
alias jestjs='frontend jestjs'
2019-01-12 15:47:23 +00:00
alias jquery='frontend jquery'
alias lodash='frontend lodash'
alias mdn='frontend mdn'
2019-10-24 19:09:05 +00:00
alias nodejs='frontend nodejs'
2019-01-12 15:47:23 +00:00
alias npmjs='frontend npmjs'
2020-06-11 14:41:32 +00:00
alias packagephobia='frontend packagephobia'
2019-01-12 15:47:23 +00:00
alias qunit='frontend qunit'
alias reactjs='frontend reactjs'
alias smacss='frontend smacss'
alias stackoverflow='frontend stackoverflow'
2019-10-24 19:09:05 +00:00
alias typescript='frontend typescript'
2019-01-12 15:47:23 +00:00
alias unheap='frontend unheap'
2019-10-24 19:09:05 +00:00
alias vuejs='frontend vuejs'
function _frontend_fallback() {
local url
if [[ "$FRONTEND_SEARCH_FALLBACK" == duckduckgo ]]; then
url="https://duckduckgo.com/?sites=$1&q="
else
url="https://google.com/search?as_sitesearch=$1&as_q="
fi
echo "$url"
}
2019-01-12 15:47:23 +00:00
function frontend() {
emulate -L zsh
# define search context URLS
typeset -A urls
urls=(
2019-10-24 19:09:05 +00:00
angular 'https://angular.io/?search='
angularjs $(_frontend_fallback 'angularjs.org')
bem $(_frontend_fallback 'bem.info')
2019-01-12 15:47:23 +00:00
bootsnipp 'https://bootsnipp.com/search?q='
2019-10-24 19:09:05 +00:00
bundlephobia 'https://bundlephobia.com/result?p='
2019-01-12 15:47:23 +00:00
caniuse 'https://caniuse.com/#search='
codepen 'https://codepen.io/search?q='
compassdoc 'http://compass-style.org/search?q='
cssflow 'http://www.cssflow.com/search?q='
dartlang 'https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart:'
2019-10-24 19:09:05 +00:00
emberjs $(_frontend_fallback 'emberjs.com/')
flowtype $(_frontend_fallback 'flow.org/en/docs/')
2019-01-12 15:47:23 +00:00
fontello 'http://fontello.com/#search='
2019-10-24 19:09:05 +00:00
github 'https://github.com/search?q='
html5please 'https://html5please.com/#'
jestjs $(_frontend_fallback 'jestjs.io')
2019-01-12 15:47:23 +00:00
jquery 'https://api.jquery.com/?s='
lodash 'https://devdocs.io/lodash/index#'
mdn 'https://developer.mozilla.org/search?q='
2019-10-24 19:09:05 +00:00
nodejs $(_frontend_fallback 'nodejs.org/en/docs/')
2019-01-12 15:47:23 +00:00
npmjs 'https://www.npmjs.com/search?q='
2020-06-11 14:41:32 +00:00
packagephobia 'https://packagephobia.now.sh/result?p='
2019-01-12 15:47:23 +00:00
qunit 'https://api.qunitjs.com/?s='
2019-10-24 19:09:05 +00:00
reactjs $(_frontend_fallback 'reactjs.org/')
smacss $(_frontend_fallback 'smacss.com')
2019-01-12 15:47:23 +00:00
stackoverflow 'https://stackoverflow.com/search?q='
2019-10-24 19:09:05 +00:00
typescript $(_frontend_fallback 'www.typescriptlang.org/docs')
2019-01-12 15:47:23 +00:00
unheap 'http://www.unheap.com/?s='
2019-10-24 19:09:05 +00:00
vuejs $(_frontend_fallback 'vuejs.org')
2019-01-12 15:47:23 +00:00
)
# show help for command list
if [[ $# -lt 2 ]]
then
print -P "Usage: frontend %Ucontext%u %Uterm%u [...%Umore%u] (or just: %Ucontext%u %Uterm%u [...%Umore%u])"
print -P ""
print -P "%Uterm%u and what follows is what will be searched for in the %Ucontext%u website,"
print -P "and %Ucontext%u is one of the following:"
print -P ""
2020-06-11 14:41:32 +00:00
print -P " angular, angularjs, bem, bootsnipp, caniuse, codepen, compassdoc, cssflow, packagephobia"
2019-10-24 19:09:05 +00:00
print -P " dartlang, emberjs, fontello, flowtype, github, html5please, jestjs, jquery, lodash,"
print -P " mdn, npmjs, nodejs, qunit, reactjs, smacss, stackoverflow, unheap, vuejs, bundlephobia"
2019-01-12 15:47:23 +00:00
print -P ""
print -P "For example: frontend npmjs mocha (or just: npmjs mocha)."
print -P ""
return 1
fi
# check whether the search context is supported
if [[ -z "$urls[$1]" ]]
then
echo "Search context \"$1\" currently not supported."
echo ""
echo "Valid contexts are:"
echo ""
2020-06-11 14:41:32 +00:00
echo " angular, angularjs, bem, bootsnipp, caniuse, codepen, compassdoc, cssflow, packagephobia"
2019-10-24 19:09:05 +00:00
echo " dartlang, emberjs, fontello, github, html5please, jest, jquery, lodash,"
echo " mdn, npmjs, nodejs, qunit, reactjs, smacss, stackoverflow, unheap, vuejs, bundlephobia"
2019-01-12 15:47:23 +00:00
echo ""
return 1
fi
# build search url:
2019-10-24 19:09:05 +00:00
# join arguments passed with '%20', then append to search context URL
2019-01-12 15:47:23 +00:00
# TODO substitute for proper urlencode method
2019-10-24 19:09:05 +00:00
url="${urls[$1]}${(j:%20:)@[2,-1]}"
2019-01-12 15:47:23 +00:00
echo "Opening $url ..."
open_command "$url"
}