build 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/usr/bin/env bash
  2. export GOPATH=$PWD
  3. LAST_CMD=
  4. APP_NAME="main"
  5. RED='\033[0;31m' # red
  6. GRN='\033[0;32m' # green
  7. YLO='\033[0;33m' # yellow
  8. CLR='\033[0m' # clear color
  9. BLD='\033[1m' # BOLD-weight
  10. function prntg {
  11. echo -e "${GRN}${1}${CLR}"
  12. }
  13. function prntr {
  14. echo -e "${RED}${1}${CLR}"
  15. }
  16. function prnty {
  17. echo -e "${YLO}${1}${CLR}"
  18. }
  19. function prntb {
  20. echo -e "${BLD}${1}${CLR}"
  21. }
  22. function set_gvar {
  23. eval "${1}="${2}""
  24. }
  25. function opt_set {
  26. [[ ${1} -eq 1 ]] && prntg "${2}" || prnty "${3}"
  27. }
  28. function error_halt {
  29. if [ ${1} -ne 0 ]; then
  30. read -p "$(prntr "Error") Press any key to continue"
  31. fi
  32. return ${1}
  33. }
  34. function _cmd {
  35. prntb "CMD: $(prnty "${1}")"
  36. ${1}
  37. error_halt $?
  38. }
  39. function go_build {
  40. _cmd "go build ${APP_NAME}"
  41. }
  42. function go_install {
  43. _cmd "go install ${APP_NAME}"
  44. }
  45. function go_run {
  46. _cmd "./bin/${APP_NAME}"
  47. read -p "Press any key to continue"
  48. }
  49. function main {
  50. clear
  51. echo "i: install b: build r: run"
  52. echo "x: exit"
  53. read -p "Option(s) $([[ -z ${LAST_CMD} ]] && echo "" || echo "[${LAST_CMD}]"): " REPLY
  54. if [ -z ${REPLY} ]; then
  55. REPLY="${LAST_CMD}"
  56. fi
  57. LAST_CMD="${REPLY}"
  58. for((I=0; I<${#REPLY};I++)); do
  59. clear
  60. case "${REPLY:${I}:1}" in
  61. [Bb] )
  62. go_build
  63. ;;
  64. [Ii] )
  65. go_install
  66. ;;
  67. [Rr] )
  68. go_run
  69. ;;
  70. [Xx] )
  71. exit 0
  72. ;;
  73. esac
  74. done
  75. main
  76. }
  77. main