frontend-search.plugin.zsh
4679 bytes
1alias angular='frontend angular'
2alias angularjs='frontend angularjs'
3alias bem='frontend bem'
4alias bootsnipp='frontend bootsnipp'
5alias bundlephobia='frontend bundlephobia'
6alias caniuse='frontend caniuse'
7alias codepen='frontend codepen'
8alias compassdoc='frontend compassdoc'
9alias cssflow='frontend cssflow'
10alias dartlang='frontend dartlang'
11alias emberjs='frontend emberjs'
12alias flowtype='frontend flowtype'
13alias fontello='frontend fontello'
14alias github='frontend github'
15alias html5please='frontend html5please'
16alias jestjs='frontend jestjs'
17alias jquery='frontend jquery'
18alias lodash='frontend lodash'
19alias mdn='frontend mdn'
20alias nodejs='frontend nodejs'
21alias npmjs='frontend npmjs'
22alias packagephobia='frontend packagephobia'
23alias qunit='frontend qunit'
24alias reactjs='frontend reactjs'
25alias smacss='frontend smacss'
26alias stackoverflow='frontend stackoverflow'
27alias typescript='frontend typescript'
28alias unheap='frontend unheap'
29alias vuejs='frontend vuejs'
30alias nextjs='frontend nextjs'
31
32function _frontend_fallback() {
33 if [[ "$FRONTEND_SEARCH_FALLBACK_LUCKY" == "true" ]]; then
34 case true in
35 *) echo "https://duckduckgo.com/?q=!ducky+site%3A$1+" ;;
36 esac
37 else
38 case "$FRONTEND_SEARCH_FALLBACK" in
39 duckduckgo) echo "https://duckduckgo.com/?sites=$1&q=" ;;
40 *) echo "https://google.com/search?as_sitesearch=$1&as_q=" ;;
41 esac
42 fi
43}
44
45function frontend() {
46 emulate -L zsh
47
48 # define search context URLS
49 local -A urls
50 urls=(
51 angular 'https://angular.io/?search='
52 angularjs $(_frontend_fallback 'angularjs.org')
53 bem $(_frontend_fallback 'bem.info')
54 bootsnipp 'https://bootsnipp.com/search?q='
55 bundlephobia 'https://bundlephobia.com/result?p='
56 caniuse 'https://caniuse.com/#search='
57 codepen 'https://codepen.io/search/pens?q='
58 compassdoc 'http://compass-style.org/search?q='
59 cssflow 'http://www.cssflow.com/search?q='
60 dartlang 'https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart:'
61 emberjs $(_frontend_fallback 'emberjs.com/')
62 flowtype $(_frontend_fallback 'flow.org/en/docs/')
63 fontello 'http://fontello.com/#search='
64 github 'https://github.com/search?q='
65 html5please 'https://html5please.com/#'
66 jestjs $(_frontend_fallback 'jestjs.io')
67 jquery 'https://api.jquery.com/?s='
68 lodash 'https://devdocs.io/lodash/index#'
69 mdn 'https://developer.mozilla.org/search?q='
70 nodejs $(_frontend_fallback 'nodejs.org/en/docs/')
71 npmjs 'https://www.npmjs.com/search?q='
72 packagephobia 'https://packagephobia.now.sh/result?p='
73 qunit 'https://api.qunitjs.com/?s='
74 reactjs $(_frontend_fallback 'reactjs.org/')
75 smacss $(_frontend_fallback 'smacss.com')
76 stackoverflow 'https://stackoverflow.com/search?q='
77 typescript $(_frontend_fallback 'www.typescriptlang.org/docs')
78 unheap 'http://www.unheap.com/?s='
79 vuejs $(_frontend_fallback 'vuejs.org')
80 nextjs $(_frontend_fallback 'nextjs.org')
81 )
82
83 # show help for command list
84 if [[ $# -lt 2 ]]; then
85 print -P "Usage: frontend %Ucontext%u %Uterm%u [...%Umore%u] (or just: %Ucontext%u %Uterm%u [...%Umore%u])"
86 print -P ""
87 print -P "%Uterm%u and what follows is what will be searched for in the %Ucontext%u website,"
88 print -P "and %Ucontext%u is one of the following:"
89 print -P ""
90 print -P " angular, angularjs, bem, bootsnipp, caniuse, codepen, compassdoc, cssflow, packagephobia"
91 print -P " dartlang, emberjs, fontello, flowtype, github, html5please, jestjs, jquery, lodash,"
92 print -P " mdn, npmjs, nodejs, qunit, reactjs, smacss, stackoverflow, unheap, vuejs, bundlephobia, nextjs"
93 print -P ""
94 print -P "For example: frontend npmjs mocha (or just: npmjs mocha)."
95 print -P ""
96 return 1
97 fi
98
99 # check whether the search context is supported
100 if [[ -z "$urls[$1]" ]]; then
101 echo "Search context \"$1\" currently not supported."
102 echo ""
103 echo "Valid contexts are:"
104 echo ""
105 echo " angular, angularjs, bem, bootsnipp, caniuse, codepen, compassdoc, cssflow, packagephobia"
106 echo " dartlang, emberjs, fontello, github, html5please, jest, jquery, lodash,"
107 echo " mdn, npmjs, nodejs, qunit, reactjs, smacss, stackoverflow, unheap, vuejs, bundlephobia, nextjs"
108 echo ""
109 return 1
110 fi
111
112 # build search url:
113 # join arguments passed with '%20', then append to search context URL
114 url="${urls[$1]}$(omz_urlencode -P ${@[2,-1]})"
115
116 echo "Opening $url ..."
117
118 open_command "$url"
119}