frontend-search.plugin.zsh 4.6 KB

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