frontend-search.plugin.zsh 4.3 KB

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