1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- #!/usr/bin/env bash
- export GOPATH=$PWD
- LAST_CMD=
- APP_NAME="main"
- RED='\033[0;31m' # red
- GRN='\033[0;32m' # green
- YLO='\033[0;33m' # yellow
- CLR='\033[0m' # clear color
- BLD='\033[1m' # BOLD-weight
- function prntg {
- echo -e "${GRN}${1}${CLR}"
- }
- function prntr {
- echo -e "${RED}${1}${CLR}"
- }
- function prnty {
- echo -e "${YLO}${1}${CLR}"
- }
- function prntb {
- echo -e "${BLD}${1}${CLR}"
- }
- function set_gvar {
- eval "${1}="${2}""
- }
- function opt_set {
- [[ ${1} -eq 1 ]] && prntg "${2}" || prnty "${3}"
- }
- function error_halt {
- if [ ${1} -ne 0 ]; then
- read -p "$(prntr "Error") Press any key to continue"
- fi
- return ${1}
- }
- function _cmd {
- prntb "CMD: $(prnty "${1}")"
- ${1}
- error_halt $?
- }
- function go_build {
- _cmd "go build ${APP_NAME}"
- }
- function go_install {
- _cmd "go install ${APP_NAME}"
- }
- function go_run {
- _cmd "./bin/${APP_NAME}"
- read -p "Press any key to continue"
- }
- function main {
- clear
- echo "i: install b: build r: run"
- echo "x: exit"
- read -p "Option(s) $([[ -z ${LAST_CMD} ]] && echo "" || echo "[${LAST_CMD}]"): " REPLY
- if [ -z ${REPLY} ]; then
- REPLY="${LAST_CMD}"
- fi
- LAST_CMD="${REPLY}"
- for((I=0; I<${#REPLY};I++)); do
- clear
- case "${REPLY:${I}:1}" in
- [Bb] )
- go_build
- ;;
- [Ii] )
- go_install
- ;;
- [Rr] )
- go_run
- ;;
- [Xx] )
- exit 0
- ;;
- esac
- done
- main
- }
- main
|