frontend-search.plugin.zsh 4.3 KB

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