frontend-search.plugin.zsh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. # frontend from terminal
  2. function frontend() {
  3. # get the open command
  4. local open_cmd
  5. if [[ $(uname -s) == 'Darwin' ]]; then
  6. open_cmd='open'
  7. else
  8. open_cmd='xdg-open'
  9. fi
  10. # no keyword provided, simply show how call methods
  11. if [[ $# -le 1 ]]; then
  12. echo "Please provide a search-content and a search-term for app.\nEx:\nfrontend <search-content> <search-term>\n"
  13. return 1
  14. fi
  15. # check whether the search engine is supported
  16. if [[ ! $1 =~ '(jquery|mdn|compass|html5please|caniuse|aurajs|dartlang|qunit|fontello|bootsnipp|cssflow|codepen|unheap|bem|smacss|angularjs|reactjs|emberjs|stackoverflow)' ]];
  17. then
  18. echo "Search valid search content $1 not supported."
  19. echo "Valid contents: (formats 'frontend <search-content>' or '<search-content>')"
  20. echo "* jquery"
  21. echo "* mdn"
  22. echo "* compass"
  23. echo "* html5please"
  24. echo "* caniuse"
  25. echo "* aurajs"
  26. echo "* dartlang"
  27. echo "* lodash"
  28. echo "* qunit"
  29. echo "* fontello"
  30. echo "* bootsnipp"
  31. echo "* cssflow"
  32. echo "* codepen"
  33. echo "* unheap"
  34. echo "* bem"
  35. echo "* smacss"
  36. echo "* angularjs"
  37. echo "* reactjs"
  38. echo "* emberjs"
  39. echo "* stackoverflow"
  40. echo ""
  41. return 1
  42. fi
  43. local url="http://"
  44. local query=""
  45. case "$1" in
  46. "jquery")
  47. url="${url}api.jquery.com"
  48. url="${url}/?s=$2" ;;
  49. "mdn")
  50. url="${url}developer.mozilla.org"
  51. url="${url}/search?q=$2" ;;
  52. "compass")
  53. url="${url}compass-style.org"
  54. url="${url}/search?q=$2" ;;
  55. "html5please")
  56. url="${url}html5please.com"
  57. url="${url}/#$2" ;;
  58. "caniuse")
  59. url="${url}caniuse.com"
  60. url="${url}/#search=$2" ;;
  61. "aurajs")
  62. url="${url}aurajs.com"
  63. url="${url}/api/#stq=$2" ;;
  64. "dartlang")
  65. url="${url}api.dartlang.org/apidocs/channels/stable/dartdoc-viewer"
  66. url="${url}/dart-$2" ;;
  67. "qunit")
  68. url="${url}api.qunitjs.com"
  69. url="${url}/?s=$2" ;;
  70. "fontello")
  71. url="${url}fontello.com"
  72. url="${url}/#search=$2" ;;
  73. "bootsnipp")
  74. url="${url}bootsnipp.com"
  75. url="${url}/search?q=$2" ;;
  76. "cssflow")
  77. url="${url}cssflow.com"
  78. url="${url}/search?q=$2" ;;
  79. "codepen")
  80. url="${url}codepen.io"
  81. url="${url}/search?q=$2" ;;
  82. "unheap")
  83. url="${url}www.unheap.com"
  84. url="${url}/?s=$2" ;;
  85. "bem")
  86. url="${url}google.com"
  87. url="${url}/search?as_q=$2&as_sitesearch=bem.info" ;;
  88. "smacss")
  89. url="${url}google.com"
  90. url="${url}/search?as_q=$2&as_sitesearch=smacss.com" ;;
  91. "angularjs")
  92. url="${url}google.com"
  93. url="${url}/search?as_q=$2&as_sitesearch=angularjs.org" ;;
  94. "reactjs")
  95. url="${url}google.com"
  96. url="${url}/search?as_q=$2&as_sitesearch=facebook.github.io/react" ;;
  97. "emberjs")
  98. url="${url}emberjs.com"
  99. url="${url}/api/#stq=$2&stp=1" ;;
  100. "stackoverflow")
  101. url="${url}https://stackoverflow.com"
  102. url="${url}/search?q=$2" ;;
  103. *) echo "INVALID PARAM!"
  104. return ;;
  105. esac
  106. echo "$url"
  107. $open_cmd "$url"
  108. }
  109. # javascript
  110. alias jquery='frontend jquery'
  111. alias mdn='frontend mdn'
  112. # pre processors frameworks
  113. alias compassdoc='frontend compass'
  114. # important links
  115. alias html5please='frontend html5please'
  116. alias caniuse='frontend caniuse'
  117. # components and libraries
  118. alias aurajs='frontend aurajs'
  119. alias dartlang='frontend dartlang'
  120. alias lodash='frontend lodash'
  121. #tests
  122. alias qunit='frontend qunit'
  123. #fonts
  124. alias fontello='frontend fontello'
  125. # snippets
  126. alias bootsnipp='frontend bootsnipp'
  127. alias cssflow='frontend cssflow'
  128. alias codepen='frontend codepen'
  129. alias unheap='frontend unheap'
  130. # css architecture
  131. alias bem='frontend bem'
  132. alias smacss='frontend smacss'
  133. # frameworks
  134. alias angularjs='frontend angularjs'
  135. alias reactjs='frontend reactjs'
  136. alias emberjs='frontend emberjs'
  137. # search websites
  138. alias stackoverflow='frontend stackoverflow'