From f1472f1f6462d391a14ec80157365500f7a11b3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Sun, 30 Aug 2015 00:09:15 +0200 Subject: [PATCH 1/5] Simplify frontend-search function with assoc array Also adds the lodash URL (which was missing) and uses https on those websites that support it. --- .../frontend-search.plugin.zsh | 100 ++++++------------ 1 file changed, 32 insertions(+), 68 deletions(-) diff --git a/plugins/frontend-search/frontend-search.plugin.zsh b/plugins/frontend-search/frontend-search.plugin.zsh index e47735a6..3afc3336 100644 --- a/plugins/frontend-search/frontend-search.plugin.zsh +++ b/plugins/frontend-search/frontend-search.plugin.zsh @@ -1,6 +1,33 @@ # frontend from terminal function frontend() { + emulate -L zsh + + # define search content URLS + typeset -A urls + urls=( + angularjs 'https://google.com/search?as_sitesearch=angularjs.org&as_q=' + aurajs 'http://aurajs.com/api/#stq=' + bem 'https://google.com/search?as_sitesearch=bem.info&as_q=' + bootsnipp 'http://bootsnipp.com/search?q=' + caniuse 'http://caniuse.com/#search=' + codepen 'http://codepen.io/search?q=' + compass '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 'http://emberjs.com/api/#stp=1&stq=' + fontello 'http://fontello.com/#search=' + html5please 'http://html5please.com/#' + jquery 'https://api.jquery.com/?s=' + lodash 'https://devdocs.io/lodash/index#' + mdn 'https://developer.mozilla.org/search?q=' + npmjs 'https://www.npmjs.com/search?q=' + 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 'http://stackoverflow.com/search?q=' + unheap 'http://www.unheap.com/?s=' + ) # no keyword provided, simply show how call methods if [[ $# -le 1 ]]; then @@ -9,7 +36,7 @@ function frontend() { fi # check whether the search engine is supported - if [[ ! $1 =~ '(jquery|mdn|compass|html5please|caniuse|aurajs|dartlang|qunit|fontello|bootsnipp|cssflow|codepen|unheap|bem|smacss|angularjs|reactjs|emberjs|stackoverflow|npmjs)' ]]; + if [[ -z "$urls[$1]" ]]; then then echo "Search valid search content $1 not supported." echo "Valid contents: (formats 'frontend ' or '')" @@ -39,73 +66,10 @@ function frontend() { return 1 fi - local url="http://" - local query="" - - case "$1" in - "jquery") - url="${url}api.jquery.com" - url="${url}/?s=$2" ;; - "mdn") - url="${url}developer.mozilla.org" - url="${url}/search?q=$2" ;; - "compass") - url="${url}compass-style.org" - url="${url}/search?q=$2" ;; - "html5please") - url="${url}html5please.com" - url="${url}/#$2" ;; - "caniuse") - url="${url}caniuse.com" - url="${url}/#search=$2" ;; - "aurajs") - url="${url}aurajs.com" - url="${url}/api/#stq=$2" ;; - "dartlang") - url="${url}api.dartlang.org/apidocs/channels/stable/dartdoc-viewer" - url="${url}/dart-$2" ;; - "qunit") - url="${url}api.qunitjs.com" - url="${url}/?s=$2" ;; - "fontello") - url="${url}fontello.com" - url="${url}/#search=$2" ;; - "bootsnipp") - url="${url}bootsnipp.com" - url="${url}/search?q=$2" ;; - "cssflow") - url="${url}cssflow.com" - url="${url}/search?q=$2" ;; - "codepen") - url="${url}codepen.io" - url="${url}/search?q=$2" ;; - "unheap") - url="${url}www.unheap.com" - url="${url}/?s=$2" ;; - "bem") - url="${url}google.com" - url="${url}/search?as_q=$2&as_sitesearch=bem.info" ;; - "smacss") - url="${url}google.com" - url="${url}/search?as_q=$2&as_sitesearch=smacss.com" ;; - "angularjs") - url="${url}google.com" - url="${url}/search?as_q=$2&as_sitesearch=angularjs.org" ;; - "reactjs") - url="${url}google.com" - url="${url}/search?as_q=$2&as_sitesearch=facebook.github.io/react" ;; - "emberjs") - url="${url}emberjs.com" - url="${url}/api/#stq=$2&stp=1" ;; - "stackoverflow") - url="${url}stackoverflow.com" - url="${url}/search?q=$2" ;; - "npmjs") - url="${url}www.npmjs.com" - url="${url}/search?q=$2" ;; - *) echo "INVALID PARAM!" - return ;; - esac + # build search url: + # join arguments passed with '+', then append to search engine URL + # TODO substitute for proper urlencode method + url="${urls[$1]}${(j:+:)@[2,-1]}" echo "$url" From ff706f3ef8fd632d93e2c347d32c62f15b17c25c Mon Sep 17 00:00:00 2001 From: willmendesneto Date: Thu, 3 Jul 2014 22:53:00 -0300 Subject: [PATCH 2/5] Add "help" method in "frontend-search" plugin --- plugins/frontend-search/README.md | 9 ++++++- .../frontend-search.plugin.zsh | 26 +++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/plugins/frontend-search/README.md b/plugins/frontend-search/README.md index b8e96ea4..bf8a4bc0 100644 --- a/plugins/frontend-search/README.md +++ b/plugins/frontend-search/README.md @@ -17,9 +17,16 @@ plugins=( ... frontend-search) ## Commands ## -All command searches are accept only in format +All command searches are accept only in formats * `frontend ` +* ` ` + +For more informations, please run help command (are similars) + +* `frontend -h` +* `frontend --help` +* `frontend help` The search content are diff --git a/plugins/frontend-search/frontend-search.plugin.zsh b/plugins/frontend-search/frontend-search.plugin.zsh index 3afc3336..08930ddc 100644 --- a/plugins/frontend-search/frontend-search.plugin.zsh +++ b/plugins/frontend-search/frontend-search.plugin.zsh @@ -29,14 +29,36 @@ function frontend() { unheap 'http://www.unheap.com/?s=' ) + # show help for commands list + if [[ $1 =~ '(help|--help|-h)' ]] + then + echo "Usage:" + echo "\n\tfrontend \n\t\n\tfrontend " + echo "" + echo "Where is one of:" + echo "jquery, mdn, compass, html5please, caniuse, aurajs, dartlang, qunit, fontello," + echo "bootsnipp, cssflow, codepen, unheap, bem, smacss, angularjs, reactjs, emberjs" + echo "help" + echo "" + echo "Where is a term to search in allowed repositories" + echo "" + echo "frontend --help show plugin help" + echo "frontend -h show plugin help" + echo "" + echo "It is allowed to directly access all search contents." + echo "" + return 1 + fi + # no keyword provided, simply show how call methods - if [[ $# -le 1 ]]; then + if [[ $# -le 1 ]] + then echo "Please provide a search-content and a search-term for app.\nEx:\nfrontend \n" return 1 fi # check whether the search engine is supported - if [[ -z "$urls[$1]" ]]; then + if [[ -z "$urls[$1]" ]] then echo "Search valid search content $1 not supported." echo "Valid contents: (formats 'frontend ' or '')" From 663ac56d54d252b9de7c76346bd64a14340a51f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Mon, 31 Aug 2015 18:49:05 +0200 Subject: [PATCH 3/5] Prettify frontend help output and clean up logic --- .../frontend-search.plugin.zsh | 79 ++++++------------- 1 file changed, 24 insertions(+), 55 deletions(-) diff --git a/plugins/frontend-search/frontend-search.plugin.zsh b/plugins/frontend-search/frontend-search.plugin.zsh index 08930ddc..6eb1fed2 100644 --- a/plugins/frontend-search/frontend-search.plugin.zsh +++ b/plugins/frontend-search/frontend-search.plugin.zsh @@ -1,9 +1,7 @@ -# frontend from terminal - function frontend() { emulate -L zsh - # define search content URLS + # define search context URLS typeset -A urls urls=( angularjs 'https://google.com/search?as_sitesearch=angularjs.org&as_q=' @@ -29,74 +27,45 @@ function frontend() { unheap 'http://www.unheap.com/?s=' ) - # show help for commands list - if [[ $1 =~ '(help|--help|-h)' ]] + # show help for command list + if [[ $# -lt 2 ]] then - echo "Usage:" - echo "\n\tfrontend \n\t\n\tfrontend " - echo "" - echo "Where is one of:" - echo "jquery, mdn, compass, html5please, caniuse, aurajs, dartlang, qunit, fontello," - echo "bootsnipp, cssflow, codepen, unheap, bem, smacss, angularjs, reactjs, emberjs" - echo "help" - echo "" - echo "Where is a term to search in allowed repositories" - echo "" - echo "frontend --help show plugin help" - echo "frontend -h show plugin help" - echo "" - echo "It is allowed to directly access all search contents." - echo "" + 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 " angularjs, aurajs, bem, bootsnipp, caniuse, codepen, compass, cssflow," + print -P " dartlang, emberjs, fontello, html5please, jquery, lodash, mdn, npmjs," + print -P " qunit, reactjs, smacss, stackoverflow, unheap" + print -P "" + print -P "For example: frontend npmjs mocha (or just: npmjs mocha)." + print -P "" return 1 fi - # no keyword provided, simply show how call methods - if [[ $# -le 1 ]] - then - echo "Please provide a search-content and a search-term for app.\nEx:\nfrontend \n" - return 1 - fi - - # check whether the search engine is supported + # check whether the search context is supported if [[ -z "$urls[$1]" ]] then - echo "Search valid search content $1 not supported." - echo "Valid contents: (formats 'frontend ' or '')" - echo "* jquery" - echo "* mdn" - echo "* compass" - echo "* html5please" - echo "* caniuse" - echo "* aurajs" - echo "* dartlang" - echo "* lodash" - echo "* qunit" - echo "* fontello" - echo "* bootsnipp" - echo "* cssflow" - echo "* codepen" - echo "* unheap" - echo "* bem" - echo "* smacss" - echo "* angularjs" - echo "* reactjs" - echo "* emberjs" - echo "* stackoverflow" - echo "* npmjs" + echo "Search context \"$1\" currently not supported." + echo "" + echo "Valid contexts are:" + echo "" + echo " angularjs, aurajs, bem, bootsnipp, caniuse, codepen, compass, cssflow, " + echo " dartlang, emberjs, fontello, html5please, jquery, lodash, mdn, npmjs, " + echo " qunit, reactjs, smacss, stackoverflow, unheap" echo "" - return 1 fi # build search url: - # join arguments passed with '+', then append to search engine URL + # join arguments passed with '+', then append to search context URL # TODO substitute for proper urlencode method url="${urls[$1]}${(j:+:)@[2,-1]}" - echo "$url" + echo "Opening $url ..." open_command "$url" - } # javascript From d982e1200f1f14fa4487a45c8af4e18834092ebd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Mon, 31 Aug 2015 19:12:05 +0200 Subject: [PATCH 4/5] Reorder alias definitions --- .../frontend-search.plugin.zsh | 63 +++++++------------ 1 file changed, 22 insertions(+), 41 deletions(-) diff --git a/plugins/frontend-search/frontend-search.plugin.zsh b/plugins/frontend-search/frontend-search.plugin.zsh index 6eb1fed2..2fd5416b 100644 --- a/plugins/frontend-search/frontend-search.plugin.zsh +++ b/plugins/frontend-search/frontend-search.plugin.zsh @@ -1,3 +1,25 @@ +alias angularjs='frontend angularjs' +alias aurajs='frontend aurajs' +alias bem='frontend bem' +alias bootsnipp='frontend bootsnipp' +alias caniuse='frontend caniuse' +alias codepen='frontend codepen' +alias compass='frontend compass' +alias cssflow='frontend cssflow' +alias dartlang='frontend dartlang' +alias emberjs='frontend emberjs' +alias fontello='frontend fontello' +alias html5please='frontend html5please' +alias jquery='frontend jquery' +alias lodash='frontend lodash' +alias mdn='frontend mdn' +alias npmjs='frontend npmjs' +alias qunit='frontend qunit' +alias reactjs='frontend reactjs' +alias smacss='frontend smacss' +alias stackoverflow='frontend stackoverflow' +alias unheap='frontend unheap' + function frontend() { emulate -L zsh @@ -67,44 +89,3 @@ function frontend() { open_command "$url" } - -# javascript -alias jquery='frontend jquery' -alias mdn='frontend mdn' - -# pre processors frameworks -alias compassdoc='frontend compass' - -# important links -alias html5please='frontend html5please' -alias caniuse='frontend caniuse' - -# components and libraries -alias aurajs='frontend aurajs' -alias dartlang='frontend dartlang' -alias lodash='frontend lodash' - -#tests -alias qunit='frontend qunit' - -#fonts -alias fontello='frontend fontello' - -# snippets -alias bootsnipp='frontend bootsnipp' -alias cssflow='frontend cssflow' -alias codepen='frontend codepen' -alias unheap='frontend unheap' - -# css architecture -alias bem='frontend bem' -alias smacss='frontend smacss' - -# frameworks -alias angularjs='frontend angularjs' -alias reactjs='frontend reactjs' -alias emberjs='frontend emberjs' - -# search websites -alias stackoverflow='frontend stackoverflow' -alias npmjs='frontend npmjs' From c481c62bc996cfe22417621dfd96c4267eb1e740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Mon, 31 Aug 2015 19:17:16 +0200 Subject: [PATCH 5/5] Refactor and clear up README file --- plugins/frontend-search/README.md | 107 ++++++++++++------------------ 1 file changed, 41 insertions(+), 66 deletions(-) diff --git a/plugins/frontend-search/README.md b/plugins/frontend-search/README.md index bf8a4bc0..d0bc5589 100644 --- a/plugins/frontend-search/README.md +++ b/plugins/frontend-search/README.md @@ -1,83 +1,60 @@ -## Rationale ## +## Introduction ## -> Searches for your Frontend contents more easier +> Searches for your frontend web development made easier -## Instalation ## +## Installation ## +Open your `~/.zshrc` file and enable the `frontend-search` plugin: -Open your `.zshrc` file and load `frontend-search` plugin +```zsh + +plugins=( ... frontend-search) -```bash -... -plugins=( ... frontend-search) -... ``` -## Commands ## +## Usage ## -All command searches are accept only in formats +You can use the frontend-search plugin in these two forms: -* `frontend ` -* ` ` +* `frontend [more terms if you want]` +* ` [more terms if you want]` -For more informations, please run help command (are similars) +For example, these two are equivalent: -* `frontend -h` -* `frontend --help` -* `frontend help` +```zsh +$ frontend angularjs dependency injection +$ angularjs dependency injection +``` -The search content are +Available search contexts are: -* `jquery ` -* `mdn ` -* `compass ` -* `html5please ` -* `caniuse ` -* `aurajs ` -* `dartlang ` -* `lodash ` -* `qunit ` -* `fontello ` -* `bootsnipp ` -* `cssflow ` -* `codepen ` -* `unheap ` -* `bem &as_sitesearch=bem.info>` -* `smacss &as_sitesearch=smacss.com>` -* `angularjs &as_sitesearch=angularjs.org>` -* `reactjs &as_sitesearch=facebook.github.io/react>` -* `emberjs ` -* `stackoverflow ` -* `npmjs ` +| context | URL | +|---------------|--------------------------------------------------------------------------| +| angularjs | `https://google.com/search?as_sitesearch=angularjs.org&as_q=` | +| aurajs | `http://aurajs.com/api/#stq=` | +| bem | `https://google.com/search?as_sitesearch=bem.info&as_q=` | +| bootsnipp | `http://bootsnipp.com/search?q=` | +| caniuse | `http://caniuse.com/#search=` | +| codepen | `http://codepen.io/search?q=` | +| compass | `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 | `http://emberjs.com/api/#stp=1&stq=` | +| fontello | `http://fontello.com/#search=` | +| html5please | `http://html5please.com/#` | +| jquery | `https://api.jquery.com/?s=` | +| lodash | `https://devdocs.io/lodash/index#` | +| mdn | `https://developer.mozilla.org/search?q=` | +| npmjs | `https://www.npmjs.com/search?q=` | +| 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 | `http://stackoverflow.com/search?q=` | +| unheap | `http://www.unheap.com/?s=` | - -## Aliases ## - -There are a few aliases presented as well: - -* `jquery` A shorthand for `frontend jquery` -* `mdn` A shorthand for `frontend mdn` -* `compass` A shorthand for `frontend compass` -* `html5please` A shorthand for `frontend html5please` -* `caniuse` A shorthand for `frontend caniuse` -* `aurajs` A shorthand for `frontend aurajs` -* `dartlang` A shorthand for `frontend dartlang` -* `lodash` A shorthand for `frontend lodash` -* `qunit` A shorthand for `frontend qunit` -* `fontello` A shorthand for `frontend fontello` -* `bootsnipp` A shorthand for `frontend bootsnipp` -* `cssflow` A shorthand for `frontend cssflow` -* `codepen` A shorthand for `frontend codepen` -* `unheap` A shorthand for `frontend unheap` -* `bem` A shorthand for `frontend bem` -* `smacss` A shorthand for `frontend smacss` -* `angularjs` A shorthand for `frontend angularjs` -* `reactjs` A shorthand for `frontend reactjs` -* `emberjs` A shorthand for `frontend emberjs` -* `stackoverflow` A shorthand for `frontend stackoverflow` -* `npmjs` A shorthand for `frontend npmjs` +If you want to have another context, open an Issue and tell us! ## Author @@ -86,5 +63,3 @@ There are a few aliases presented as well: + + + - -New features comming soon.