Advertisement
Guest User

Untitled

a guest
Jan 27th, 2015
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Functions ==============================================
  4.  
  5. # return 1 if global command line program installed, else 0
  6. # example
  7. # echo "node: $(program_is_installed node)"
  8. function program_is_installed {
  9. # set to 1 initially
  10. local return_=1
  11. # set to 0 if not found
  12. type $1 >/dev/null 2>&1 || { local return_=0; }
  13. # return value
  14. echo "$return_"
  15. }
  16.  
  17. # return 1 if local npm package is installed at ./node_modules, else 0
  18. # example
  19. # echo "gruntacular : $(npm_package_is_installed gruntacular)"
  20. function npm_package_is_installed {
  21. # set to 1 initially
  22. local return_=1
  23. # set to 0 if not found
  24. ls node_modules | grep $1 >/dev/null 2>&1 || { local return_=0; }
  25. # return value
  26. echo "$return_"
  27. }
  28.  
  29. # display a message in red with a cross by it
  30. # example
  31. # echo echo_fail "No"
  32. function echo_fail {
  33. # echo first argument in red
  34. printf "\e[31m✘ ${1}"
  35. # reset colours back to normal
  36. echo "\033[0m"
  37. }
  38.  
  39. # display a message in green with a tick by it
  40. # example
  41. # echo echo_fail "Yes"
  42. function echo_pass {
  43. # echo first argument in green
  44. printf "\e[32m✔ ${1}"
  45. # reset colours back to normal
  46. echo "\033[0m"
  47. }
  48.  
  49. # echo pass or fail
  50. # example
  51. # echo echo_if 1 "Passed"
  52. # echo echo_if 0 "Failed"
  53. function echo_if {
  54. if [ $1 == 1 ]; then
  55. echo_pass $2
  56. else
  57. echo_fail $2
  58. fi
  59. }
  60.  
  61. # ============================================== Functions
  62.  
  63. # command line programs
  64. echo "node $(echo_if $(program_is_installed node))"
  65. echo "grunt $(echo_if $(program_is_installed grunt))"
  66. echo "testacular $(echo_if $(program_is_installed testacular))"
  67. echo "uglifyjs $(echo_if $(program_is_installed uglifyjs))"
  68. echo "requirejs $(echo_if $(program_is_installed r.js))"
  69. echo "lodash $(echo_if $(program_is_installed lodash))"
  70. echo "gem $(echo_if $(program_is_installed gem))"
  71.  
  72. # local npm packages
  73. echo "grunt-shell $(echo_if $(npm_package_is_installed grunt-shell))"
  74. echo "grunt-hashres $(echo_if $(npm_package_is_installed grunt-hashres))"
  75. echo "gruntacular $(echo_if $(npm_package_is_installed gruntacular))"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement