frontend-search.plugin.zsh 4.4 KB

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