Last active
July 9, 2021 21:10
-
-
Save TheDutchCoder/eee35dc49ee5a55f6eaefe8ae3e316a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RED="31" | |
GREEN="32" | |
CYAN="36" | |
WHITE="97" | |
BOLDGREEN="\e[1;${GREEN}m" | |
BOLDCYAN="\e[1;${CYAN}m" | |
BOLDWHITE="\e[1;${WHITE}m" | |
ENDCOLOR="\e[0m" | |
function select_option { | |
# little helpers for terminal print control and key input | |
ESC=$( printf "\033") | |
cursor_blink_on() { printf "$ESC[?25h"; } | |
cursor_blink_off() { printf "$ESC[?25l"; } | |
cursor_to() { printf "$ESC[$1;${2:-1}H"; } | |
print_option() { printf " $1 "; } | |
print_selected() { printf "$BOLDCYAN › $1 $ENDCOLOR"; } | |
get_cursor_row() { IFS=';' read -sdR -p $'\E[6n' ROW COL; echo ${ROW#*[}; } | |
key_input() { read -s -n3 key 2>/dev/null >&2 | |
if [[ $key = $ESC[A ]]; then echo up; fi | |
if [[ $key = $ESC[B ]]; then echo down; fi | |
if [[ $key = "" ]]; then echo enter; fi; } | |
# initially print empty new lines (scroll down if at bottom of screen) | |
for opt; do printf "\n"; done | |
# determine current screen position for overwriting the options | |
local lastrow=`get_cursor_row` | |
local startrow=$(($lastrow - $#)) | |
# ensure cursor and input echoing back on upon a ctrl+c during read -s | |
trap "cursor_blink_on; stty echo; printf '\n'; exit" 2 | |
cursor_blink_off | |
local selected=0 | |
while true; do | |
# print options by overwriting the last lines | |
local idx=0 | |
for opt; do | |
cursor_to $(($startrow + $idx)) | |
if [ $idx -eq $selected ]; then | |
print_selected "$opt" | |
else | |
print_option "$opt" | |
fi | |
((idx++)) | |
done | |
# user key control | |
case `key_input` in | |
enter) break;; | |
up) ((selected--)); | |
if [ $selected -lt 0 ]; then selected=$(($# - 1)); fi;; | |
down) ((selected++)); | |
if [ $selected -ge $# ]; then selected=0; fi;; | |
esac | |
done | |
# cursor position back to normal | |
cursor_to $lastrow | |
printf "\n" | |
cursor_blink_on | |
return $selected | |
} | |
function npmaction() { | |
origdir="$PWD" | |
args=("$@") | |
method="$1 $2" | |
rest=("${args[@]:1}") | |
for arg in "${rest[@]}" | |
do | |
cd "$arg" | |
# ls -la | |
# echo "$method" | |
$method & | |
cd "$origdir" | |
done | |
} | |
function gitaction() { | |
origdir="$PWD" | |
args=("$@") | |
method="$1 $2" | |
rest=("${args[@]:1}") | |
for arg in "${rest[@]}" | |
do | |
cd "$arg" | |
# ls -la | |
# echo "$method" | |
$method & | |
cd "$origdir" | |
done | |
} | |
clear | |
printf "${BOLDGREEN} Select a category\n\n" | |
o=("amplify" "npm" "git") | |
select_option "${o[@]}" | |
c=$? | |
# amplify | |
if [[ $c == 0 ]] | |
then | |
clear | |
printf "${BOLDGREEN} Amplify commands\n\n" | |
o=("amplify push" "amplify push -y" "amplify status") | |
select_option "${o[@]}" | |
c=$? | |
if [[ $c == 0 ]] | |
then | |
# amplify push | |
clear | |
printf "${BOLDGREEN}Running ${BOLDWHITE}amplify push\n\n${BOLDCYAN}Please wait...\n\n" | |
amplify push | |
wait | |
elif [[ $c == 1 ]] | |
then | |
# amplify push -y | |
clear | |
printf "${BOLDGREEN}Running ${BOLDWHITE}amplify push -y\n\n${BOLDCYAN}Please wait...\n\n" | |
amplify push -y | |
wait | |
elif [[ $c == 2 ]] | |
then | |
# amplify push -y | |
clear | |
printf "${BOLDGREEN}Running ${BOLDWHITE}amplify status\n\n${BOLDCYAN}Please wait...\n\n" | |
amplify status | |
wait | |
fi | |
# clear | |
exit | |
# npm | |
elif [[ $c == 1 ]] | |
then | |
clear | |
printf "${BOLDGREEN} NPM commands\n\n" | |
o=("npm ci" "npm install") | |
select_option "${o[@]}" | |
c=$? | |
if [[ $c == 0 ]] | |
then | |
# npm ci | |
clear | |
printf "${BOLDGREEN} Which project would you like to npm ci?\n\n" | |
o=("all" "packages/chalk-icons" "packages/chalk-ui" "workflow" "apps/proofflow") | |
select_option "${o[@]}" | |
c=$? | |
if [[ $c == 0 ]] | |
then | |
# npm ci all projects | |
clear | |
printf "${BOLDGREEN}Running ${BOLDWHITE}npm ci${BOLDGREEN} on all projects\n\n${BOLDCYAN}Please wait...\n\n" | |
npmaction "npm ci" "${o[@]:1}" | |
wait | |
else | |
# npm ci single project | |
clear | |
printf "${BOLDGREEN}Running ${BOLDWHITE}npm ci${BOLDGREEN} on "${o[$c]}"\n\n${BOLDCYAN}Please wait...\n\n" | |
npmaction "npm ci" "${o[$c]}" | |
wait | |
fi | |
elif [[ $c == 1 ]] | |
then | |
# npm install | |
clear | |
printf "${BOLDGREEN} Which project would you like to npm install?\n\n" | |
o=("all" "packages/chalk-icons" "packages/chalk-ui" "workflow" "apps/proofflow") | |
select_option "${o[@]}" | |
c=$? | |
if [[ $c == 0 ]] | |
then | |
# npm install all projects | |
clear | |
printf "${BOLDGREEN}Running ${BOLDWHITE}npm install${BOLDGREEN} on all projects\n\n${BOLDCYAN}Please wait...\n\n" | |
npmaction "npm install" "${o[@]:1}" | |
wait | |
else | |
# npm install single project | |
clear | |
printf "${BOLDGREEN}Running ${BOLDWHITE}npm install${BOLDGREEN} on ${o[$c]}\n\n${BOLDCYAN}Please wait...\n\n" | |
npmaction "npm install" "${o[$c]}" | |
wait | |
fi | |
fi | |
# clear | |
exit | |
# git | |
elif [[ $c == 2 ]] | |
then | |
clear | |
printf "${BOLDGREEN} git commands\n\n" | |
o=("pull" "push" "force push" "rebase" "pull & rebase") | |
select_option "${o[@]}" | |
c=$? | |
if [[ $c == 0 ]] | |
then | |
# pull | |
clear | |
printf "${BOLDGREEN}Running ${BOLDWHITE}git pull${BOLDGREEN}\n\n${BOLDCYAN}Please wait...\n\n" | |
git pull | |
wait | |
elif [[ $c == 1 ]] | |
then | |
# push | |
clear | |
printf "${BOLDGREEN}Running ${BOLDWHITE}git push${BOLDGREEN}\n\n${BOLDCYAN}Please wait...\n\n" | |
git push origin -HEAD | |
wait | |
elif [[ $c == 2 ]] | |
then | |
# force push | |
clear | |
printf "${BOLDGREEN}Running ${BOLDWHITE}git force push${BOLDGREEN}\n\n${BOLDCYAN}Please wait...\n\n" | |
git push -f | |
wait | |
elif [[ $c == 3 ]] | |
then | |
# rebase | |
clear | |
printf "${BOLDGREEN}Running ${BOLDWHITE}git rebase${BOLDGREEN}\n\n${BOLDCYAN}Please wait...\n\n" | |
git rebase develop | |
wait | |
elif [[ $c == 4 ]] | |
then | |
# pull & rebase | |
clear | |
printf "${BOLDGREEN}Running ${BOLDWHITE}git pull & rebase${BOLDGREEN}\n\n${BOLDCYAN}Please wait...\n\n" | |
git checkout develop | |
git pull | |
git checkout - | |
git rebase develop | |
wait | |
fi | |
# clear | |
exit | |
fi | |
# echo "Which project do you want to install?" | |
# echo | |
# options=("all" "packages/chalk-icons" "packages/chalk-ui" "workflow" "apps/proofflow") | |
# packages=("packages/chalk-icons" "packages/chalk-ui" "workflow" "apps/proofflow") | |
# select_option "${options[@]}" | |
# option_choice=$? | |
# echo "Which install method do you want to use?" | |
# echo | |
# method=("npm ci" "npm install") | |
# select_option "${method[@]}" | |
# method_choice=$? | |
# if [[ $option_choice == 0 ]] | |
# then | |
# npmaction "${method[$method_choice]}" "${packages[@]}" | |
# wait | |
# else | |
# npmaction "${method[$method_choice]}" "${options[$option_choice]}" | |
# wait | |
# fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment