frontend-search.plugin.zsh 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. alias angularjs='frontend angularjs'
  2. alias aurajs='frontend aurajs'
  3. alias bem='frontend bem'
  4. alias bootsnipp='frontend bootsnipp'
  5. alias caniuse='frontend caniuse'
  6. alias codepen='frontend codepen'
  7. alias compassdoc='frontend compassdoc'
  8. alias cssflow='frontend cssflow'
  9. alias dartlang='frontend dartlang'
  10. alias emberjs='frontend emberjs'
  11. alias fontello='frontend fontello'
  12. alias html5please='frontend html5please'
  13. alias jquery='frontend jquery'
  14. alias lodash='frontend lodash'
  15. alias mdn='frontend mdn'
  16. alias npmjs='frontend npmjs'
  17. alias qunit='frontend qunit'
  18. alias reactjs='frontend reactjs'
  19. alias smacss='frontend smacss'
  20. alias stackoverflow='frontend stackoverflow'
  21. alias unheap='frontend unheap'
  22. function frontend() {
  23. emulate -L zsh
  24. # define search context URLS
  25. typeset -A urls
  26. urls=(
  27. angularjs 'https://google.com/search?as_sitesearch=angularjs.org&as_q='
  28. aurajs 'http://aurajs.com/api/#stq='
  29. bem 'https://google.com/search?as_sitesearch=bem.info&as_q='
  30. bootsnipp 'https://bootsnipp.com/search?q='
  31. caniuse 'https://caniuse.com/#search='
  32. codepen 'https://codepen.io/search?q='
  33. compassdoc 'http://compass-style.org/search?q='
  34. cssflow 'http://www.cssflow.com/search?q='
  35. dartlang 'https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart:'
  36. emberjs 'https://emberjs.com/api/#stp=1&stq='
  37. fontello 'http://fontello.com/#search='
  38. html5please 'http://html5please.com/#'
  39. jquery 'https://api.jquery.com/?s='
  40. lodash 'https://devdocs.io/lodash/index#'
  41. mdn 'https://developer.mozilla.org/search?q='
  42. npmjs 'https://www.npmjs.com/search?q='
  43. qunit 'https://api.qunitjs.com/?s='
  44. reactjs 'https://google.com/search?as_sitesearch=facebook.github.io/react&as_q='
  45. smacss 'https://google.com/search?as_sitesearch=smacss.com&as_q='
  46. stackoverflow 'https://stackoverflow.com/search?q='
  47. unheap 'http://www.unheap.com/?s='
  48. )
  49. # show help for command list
  50. if [[ $# -lt 2 ]]
  51. then
  52. print -P "Usage: frontend %Ucontext%u %Uterm%u [...%Umore%u] (or just: %Ucontext%u %Uterm%u [...%Umore%u])"
  53. print -P ""
  54. print -P "%Uterm%u and what follows is what will be searched for in the %Ucontext%u website,"
  55. print -P "and %Ucontext%u is one of the following:"
  56. print -P ""
  57. print -P " angularjs, aurajs, bem, bootsnipp, caniuse, codepen, compassdoc, cssflow,"
  58. print -P " dartlang, emberjs, fontello, html5please, jquery, lodash, mdn, npmjs,"
  59. print -P " qunit, reactjs, smacss, stackoverflow, unheap"
  60. print -P ""
  61. print -P "For example: frontend npmjs mocha (or just: npmjs mocha)."
  62. print -P ""
  63. return 1
  64. fi
  65. # check whether the search context is supported
  66. if [[ -z "$urls[$1]" ]]
  67. then
  68. echo "Search context \"$1\" currently not supported."
  69. echo ""
  70. echo "Valid contexts are:"
  71. echo ""
  72. echo " angularjs, aurajs, bem, bootsnipp, caniuse, codepen, compassdoc, cssflow, "
  73. echo " dartlang, emberjs, fontello, html5please, jquery, lodash, mdn, npmjs, "
  74. echo " qunit, reactjs, smacss, stackoverflow, unheap"
  75. echo ""
  76. return 1
  77. fi
  78. # build search url:
  79. # join arguments passed with '+', then append to search context URL
  80. # TODO substitute for proper urlencode method
  81. url="${urls[$1]}${(j:+:)@[2,-1]}"
  82. echo "Opening $url ..."
  83. open_command "$url"
  84. }