frontend-search.plugin.zsh 4.3 KB

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