frontend-search.plugin.zsh 3.5 KB

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