diff options
Diffstat (limited to 'oh-my-zsh/plugins/frontend-search')
-rw-r--r-- | oh-my-zsh/plugins/frontend-search/README.md | 75 | ||||
-rw-r--r-- | oh-my-zsh/plugins/frontend-search/_frontend | 161 | ||||
-rw-r--r-- | oh-my-zsh/plugins/frontend-search/frontend-search.plugin.zsh | 111 |
3 files changed, 347 insertions, 0 deletions
diff --git a/oh-my-zsh/plugins/frontend-search/README.md b/oh-my-zsh/plugins/frontend-search/README.md new file mode 100644 index 0000000..0500589 --- /dev/null +++ b/oh-my-zsh/plugins/frontend-search/README.md @@ -0,0 +1,75 @@ +## Introduction + +> Searches for your frontend web development made easier + +## Installation + +Open your `~/.zshrc` file and enable the `frontend-search` plugin: + +```zsh + +plugins=( ... frontend-search) + +``` + +## Usage + +You can use the frontend-search plugin in these two forms: + +- `frontend <context> <term> [more terms if you want]` +- `<context> <term> [more terms if you want]` + +For example, these two are equivalent: + +```zsh +$ angular dependency injection +# Will turn into ... +$ frontend angular dependency injection +``` + +Available search contexts are: + +| context | URL | +| ------------- | --------------------------------------------------------------------------- | +| angular | `https://angular.io/?search=` | +| angularjs | `https://google.com/search?as_sitesearch=angularjs.org&as_q=` | +| bem | `https://google.com/search?as_sitesearch=bem.info&as_q=` | +| bootsnipp | `https://bootsnipp.com/search?q=` | +| bundlephobia | `https://bundlephobia.com/result?p=` | +| 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:` | +| emberjs | `https://www.google.com/search?as_sitesearch=emberjs.com/&as_q=` | +| flowtype | `https://google.com/search?as_sitesearch=flow.org/en/docs/&as_q=` | +| fontello | `http://fontello.com/#search=` | +| github | `https://github.com/search?q=` | +| html5please | `https://html5please.com/#` | +| jestjs | `https://www.google.com/search?as_sitesearch=jestjs.io&as_q=` | +| jquery | `https://api.jquery.com/?s=` | +| lodash | `https://devdocs.io/lodash/index#` | +| mdn | `https://developer.mozilla.org/search?q=` | +| nodejs | `https://www.google.com/search?as_sitesearch=nodejs.org/en/docs/&as_q=` | +| npmjs | `https://www.npmjs.com/search?q=` | +| packagephobia | `https://packagephobia.now.sh/result?p=` | +| qunit | `https://api.qunitjs.com/?s=` | +| reactjs | `https://google.com/search?as_sitesearch=facebook.github.io/react&as_q=` | +| smacss | `https://google.com/search?as_sitesearch=smacss.com&as_q=` | +| stackoverflow | `https://stackoverflow.com/search?q=` | +| typescript | `https://google.com/search?as_sitesearch=www.typescriptlang.org/docs&as_q=` | +| unheap | `http://www.unheap.com/?s=` | +| vuejs | `https://www.google.com/search?as_sitesearch=vuejs.org&as_q=` | + +If you want to have another context, open an Issue and tell us! + +## Fallback search behaviour + +The plugin will use Google as a fallback if the docs site for a search context does not have a search function. You can set the fallback search engine to DuckDuckGo by setting `FRONTEND_SEARCH_FALLBACK='duckduckgo'` in your `~/.zshrc` file before Oh My Zsh is sourced. + +## Author + +**Wilson Mendes (willmendesneto)** + +- <https://twitter.com/willmendesneto> +- <https://github.com/willmendesneto> diff --git a/oh-my-zsh/plugins/frontend-search/_frontend b/oh-my-zsh/plugins/frontend-search/_frontend new file mode 100644 index 0000000..aca4920 --- /dev/null +++ b/oh-my-zsh/plugins/frontend-search/_frontend @@ -0,0 +1,161 @@ +#compdef frontend + +zstyle ':completion:*:descriptions' format '%B%d%b' +zstyle ':completion::complete:frontend:*:commands' group-name commands +zstyle ':completion::complete:frontend:*:frontend_points' group-name frontend_points +zstyle ':completion::complete:frontend::' list-grouped + +zmodload zsh/mapfile + +function _frontend() { + local CONFIG=$HOME/.frontend-search + local ret=1 + + local -a commands + local -a frontend_points + + frontend_points=( "${(f)mapfile[$CONFIG]//$HOME/~}" ) + + commands=( + 'angular: Search in Angular.io website' + 'angularjs: Search in docs.angularjs.org website' + 'bem: Search in BEM website' + 'bootsnipp: Search in bootsnipp website' + 'bundlephobia: Search in Bundlephobia website' + 'caniuse: Search in Can I Use website' + 'codepen: Search in codepen website' + 'compassdoc: Search in COMPASS website' + 'cssflow: Search in cssflow website' + 'dartlang: Search in Dart website' + 'emberjs: Search in Ember website' + 'flowtype: Search in Flowtype website' + 'fontello: Search in fontello website' + 'github: Search in GitHub website' + 'html5please: Search in HTML5 Please website' + 'jestjs: Search in Jest website' + 'jquery: Search in jQuery website' + 'lodash: Search in Lo-Dash website' + 'mdn: Search in MDN website' + 'nodejs: Search in NodeJS website' + 'npmjs: Search in npmjs website' + 'packagephobia: Search in Packagephobia website' + 'qunit: Search in Qunit website' + 'reactjs: Search in React website' + 'smacss: Search in SMACSS website' + 'stackoverflow: Search in StackOverflow website' + 'typescript: Search in TypeScript website' + 'unheap: Search in unheap website' + 'vuejs: Search in VueJS website' + ) + + _arguments -C \ + '1: :->first_arg' \ + '2: :->second_arg' && ret=0 + + case $state in + first_arg) + _describe -t frontend_points "Warp points" frontend_points && ret=0 + _describe -t commands "Commands" commands && ret=0 + ;; + second_arg) + case $words[2] in + jquery) + _describe -t points "Warp points" frontend_points && ret=0 + ;; + mdn) + _describe -t points "Warp points" frontend_points && ret=0 + ;; + compassdoc) + _describe -t points "Warp points" frontend_points && ret=0 + ;; + html5please) + _describe -t points "Warp points" frontend_points && ret=0 + ;; + caniuse) + _describe -t points "Warp points" frontend_points && ret=0 + ;; + dartlang) + _describe -t points "Warp points" frontend_points && ret=0 + ;; + lodash) + _describe -t points "Warp points" frontend_points && ret=0 + ;; + qunit) + _describe -t points "Warp points" frontend_points && ret=0 + ;; + fontello) + _describe -t points "Warp points" frontend_points && ret=0 + ;; + github) + _describe -t points "Warp points" frontend_points && ret=0 + ;; + bootsnipp) + _describe -t points "Warp points" frontend_points && ret=0 + ;; + cssflow) + _describe -t points "Warp points" frontend_points && ret=0 + ;; + codepen) + _describe -t points "Warp points" frontend_points && ret=0 + ;; + unheap) + _describe -t points "Warp points" frontend_points && ret=0 + ;; + bem) + _describe -t points "Warp points" frontend_points && ret=0 + ;; + smacss) + _describe -t points "Warp points" frontend_points && ret=0 + ;; + angularjs) + _describe -t points "Warp points" frontend_points && ret=0 + ;; + reactjs) + _describe -t points "Warp points" frontend_points && ret=0 + ;; + emberjs) + _describe -t points "Warp points" frontend_points && ret=0 + ;; + stackoverflow) + _describe -t points "Warp points" frontend_points && ret=0 + ;; + npmjs) + _describe -t points "Warp points" frontend_points && ret=0 + ;; + bundlephobia) + _describe -t points "Warp points" frontend_points && ret=0 + ;; + packagephobia) + _describe -t points "Warp points" frontend_points && ret=0 + ;; + flowtype) + _describe -t points "Warp points" frontend_points && ret=0 + ;; + typescript) + _describe -t points "Warp points" frontend_points && ret=0 + ;; + vuejs) + _describe -t points "Warp points" frontend_points && ret=0 + ;; + nodejs) + _describe -t points "Warp points" frontend_points && ret=0 + ;; + jestjs) + _describe -t points "Warp points" frontend_points && ret=0 + ;; + esac + ;; + esac + + return $ret +} + +_frontend "$@" + +# Local Variables: +# mode: Shell-Script +# sh-indentation: 2 +# indent-tabs-mode: nil +# sh-basic-offset: 2 +# End: +# vim: ft=zsh sw=2 ts=2 et diff --git a/oh-my-zsh/plugins/frontend-search/frontend-search.plugin.zsh b/oh-my-zsh/plugins/frontend-search/frontend-search.plugin.zsh new file mode 100644 index 0000000..b9e2fe9 --- /dev/null +++ b/oh-my-zsh/plugins/frontend-search/frontend-search.plugin.zsh @@ -0,0 +1,111 @@ +alias angular='frontend angular' +alias angularjs='frontend angularjs' +alias bem='frontend bem' +alias bootsnipp='frontend bootsnipp' +alias bundlephobia='frontend bundlephobia' +alias caniuse='frontend caniuse' +alias codepen='frontend codepen' +alias compassdoc='frontend compassdoc' +alias cssflow='frontend cssflow' +alias dartlang='frontend dartlang' +alias emberjs='frontend emberjs' +alias flowtype='frontend flowtype' +alias fontello='frontend fontello' +alias github='frontend github' +alias html5please='frontend html5please' +alias jestjs='frontend jestjs' +alias jquery='frontend jquery' +alias lodash='frontend lodash' +alias mdn='frontend mdn' +alias nodejs='frontend nodejs' +alias npmjs='frontend npmjs' +alias packagephobia='frontend packagephobia' +alias qunit='frontend qunit' +alias reactjs='frontend reactjs' +alias smacss='frontend smacss' +alias stackoverflow='frontend stackoverflow' +alias typescript='frontend typescript' +alias unheap='frontend unheap' +alias vuejs='frontend vuejs' + +function _frontend_fallback() { + case "$FRONTEND_SEARCH_FALLBACK" in + duckduckgo) echo "https://duckduckgo.com/?sites=$1&q=" ;; + *) echo "https://google.com/search?as_sitesearch=$1&as_q=" ;; + esac +} + +function frontend() { + emulate -L zsh + + # define search context URLS + local -A urls + urls=( + angular 'https://angular.io/?search=' + angularjs $(_frontend_fallback 'angularjs.org') + bem $(_frontend_fallback 'bem.info') + bootsnipp 'https://bootsnipp.com/search?q=' + bundlephobia 'https://bundlephobia.com/result?p=' + caniuse 'https://caniuse.com/#search=' + codepen 'https://codepen.io/search/pens?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:' + emberjs $(_frontend_fallback 'emberjs.com/') + flowtype $(_frontend_fallback 'flow.org/en/docs/') + fontello 'http://fontello.com/#search=' + github 'https://github.com/search?q=' + html5please 'https://html5please.com/#' + jestjs $(_frontend_fallback 'jestjs.io') + jquery 'https://api.jquery.com/?s=' + lodash 'https://devdocs.io/lodash/index#' + mdn 'https://developer.mozilla.org/search?q=' + nodejs $(_frontend_fallback 'nodejs.org/en/docs/') + npmjs 'https://www.npmjs.com/search?q=' + packagephobia 'https://packagephobia.now.sh/result?p=' + qunit 'https://api.qunitjs.com/?s=' + reactjs $(_frontend_fallback 'reactjs.org/') + smacss $(_frontend_fallback 'smacss.com') + stackoverflow 'https://stackoverflow.com/search?q=' + typescript $(_frontend_fallback 'www.typescriptlang.org/docs') + unheap 'http://www.unheap.com/?s=' + vuejs $(_frontend_fallback 'vuejs.org') + ) + + # 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 "" + print -P " angular, angularjs, bem, bootsnipp, caniuse, codepen, compassdoc, cssflow, packagephobia" + print -P " dartlang, emberjs, fontello, flowtype, github, html5please, jestjs, jquery, lodash," + print -P " mdn, npmjs, nodejs, qunit, reactjs, smacss, stackoverflow, unheap, vuejs, bundlephobia" + 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 "" + echo " angular, angularjs, bem, bootsnipp, caniuse, codepen, compassdoc, cssflow, packagephobia" + echo " dartlang, emberjs, fontello, github, html5please, jest, jquery, lodash," + echo " mdn, npmjs, nodejs, qunit, reactjs, smacss, stackoverflow, unheap, vuejs, bundlephobia" + echo "" + return 1 + fi + + # build search url: + # join arguments passed with '%20', then append to search context URL + url="${urls[$1]}$(omz_urlencode -P ${@[2,-1]})" + + echo "Opening $url ..." + + open_command "$url" +} |