Last active
January 12, 2020 00:21
-
-
Save scope2229/773d92773c7826c0abdb1bd9094ab437 to your computer and use it in GitHub Desktop.
Make executable, create symbolic link to script in /usr/local/bin etc for global access. Used for rails applications running with and without docker. Can easily be used for any other development environment.
This file contains 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
#!/bin/bash | |
################################################################### | |
################################################################### | |
## ## | |
## Development environment setup for Guake ## | |
## ## | |
## Creates tabs with DIR in project directory along with ## | |
## services to be run or stopped ## | |
## Displays a menu to select your environment ## | |
## ## | |
################################################################### | |
################################################################### | |
################################################################### | |
# # | |
# VARIABLES # | |
# # | |
################################################################### | |
TAB_ARRAY=() | |
OPTION_ONE_LABEL="<ENTER LABEL HERE>" | |
OPTION_ONE_PATH=<PROJECT ROOT DIR> | |
OPTION_ONE_DOCKER_NAME="<DOCKER CONTAINER NAME>" | |
OPTION_TWO_LABEL="<ENTER LABEL HERE>" | |
OPTION_TWO_PATH=<PROJECT ROOT DIR> | |
OPTION_THREE_LABEL="<ENTER LABEL HERE>" | |
OPTION_THREE_PATH=<PROJECT ROOT DIR> | |
RESET_TERMINAL_LABEL="Reset terminal to 1 tab in the root directory" | |
EXIT_SCRIPT_LABEL="Exit script." | |
################################################################### | |
# # | |
# FUNCTIONS # | |
# # | |
################################################################### | |
check_open_tabs() { | |
TAB_ARRAY=() | |
i="0" | |
while [ "$(guake -s $i 2>&1)" = "" ] | |
do | |
TAB_ARRAY+=($(guake -g)) | |
i=$[$i+1] | |
done | |
guake -s 0 | |
sleep 0.5 | |
} | |
close_open_tabs() { | |
for index in ${!TAB_ARRAY[@]} | |
do | |
if [[ $index != 0 ]] | |
then | |
i="1" | |
sleep 0.5 | |
guake -s $[$i] --execute-command "exit" | |
i=$[$i+1] | |
fi | |
done | |
echo "TOTAL TABS OPEN ${#TAB_ARRAY[@]}" | |
} | |
delete_tabs_check() { | |
echo "OPEN TABS FOUND!" | |
read -p "WARNING: This will close your existing open tabs. Open programs from those terminals will be closed too! Y/n?" userAnswer | |
case ${userAnswer:0:1} in | |
y|Y) | |
close_open_tabs | |
check_open_tabs | |
guake -s 0 | |
;; | |
* ) | |
guake -n " " -r "Test" | |
guake -s $[${#TAB_ARRAY[@]}] | |
;; | |
esac | |
} | |
option_one() { | |
project_path=$OPTION_ONE_PATH | |
guake -r "DOCK COMP" -e "cd $OPTION_ONE_PATH" | |
guake -n $project_path -r "DOCK GUARD" | |
guake -n $project_path -r "DOCK R-CONSOLE" | |
guake -n $project_path -r "DOCK MISC" | |
guake -n $project_path -r "MISC" | |
guake -s 0 | |
wait | |
sleep 5 | |
} | |
option_one_commands() { | |
echo "sudo service postgresql stop" | |
sudo service postgresql stop | |
wait | |
sleep 4 | |
docker-compose down | |
wait | |
docker-compose up -d | |
sleep 10 | |
guake -s 1 -e "docker exec -it $OPTION_ONE_DOCKER_NAME /bin/bash" | |
wait | |
guake -e "bundle exec guard" | |
guake -s 2 -e "docker exec -it $OPTION_ONE_DOCKER_NAME /bin/bash" | |
wait | |
guake -e "rails c" | |
wait | |
guake -s 3 -e "docker exec -it $OPTION_ONE_DOCKER_NAME /bin/bash" | |
wait | |
guake -s 0 -e "docker-compose logs --tail='100' -f" | |
} | |
option_two() { | |
project_path=$OPTION_TWO_PATH | |
guake -r "RAILS S" -e "cd $OPTION_TWO_PATH && clear" | |
guake -n $project_path -r "RAILS GUARD" | |
guake -n $project_path -r "RAILS CONSOLE" | |
guake -n $project_path -r "RAILS MISC" | |
guake -n $project_path -r "MISC" | |
wait | |
guake -s 0 | |
} | |
option_two_commands() { | |
echo "Start postgresql service" | |
sudo service postgresql start | |
wait | |
docker-compose down | |
wait | |
guake -e "rails s" | |
guake -s 1 -e "bundle exec guard" | |
guake -s 2 -e "rails c" | |
guake -s 0 | |
} | |
option_three() { | |
project_path=$OPTION_THREE_PATH | |
guake -r "MAIN" -e "cd $project_path && clear" | |
guake -n $project_path -r "TEST" | |
guake -n $project_path -r "MISC" | |
guake -s 0 | |
} | |
reset_terminal() { | |
close_open_tabs | |
check_open_tabs | |
guake -r "MAIN" -e "cd ~ && clear " | |
} | |
exit_script() { | |
exit | |
} | |
################################################################### | |
# # | |
# CLI MENU # | |
# # | |
################################################################### | |
#intialize app & display menu | |
check_open_tabs | |
if [ $# -eq 0 ] | |
then | |
echo -e "\n" | |
echo "#######################################" | |
echo " Terminal setup for " | |
echo " developing applications " | |
echo " that start with all the nessesary " | |
echo " tools needed for the project " | |
echo "" | |
echo -e "#######################################\n" | |
echo " 1 :: ${OPTION_ONE_LABEL}" | |
echo " 2 :: ${OPTION_TWO_LABEL}" | |
echo " 3 :: ${OPTION_THREE_LABEL}" | |
echo " R :: ${RESET_TERMINAL_LABEL}" | |
echo " Q :: ${EXIT_SCRIPT_LABEL}" | |
echo "" | |
read -p " Input number choice 1-5: " userInput | |
else | |
echo -e "\n Starting with option: $1" | |
userInput=$1 | |
fi | |
################################################################### | |
# # | |
# OPTION_ONE # | |
# # | |
################################################################### | |
if [[ $userInput = 1 ]] | |
then | |
if [[ ${#TAB_ARRAY[@]} > 1 ]] | |
then | |
delete_tabs_check | |
fi | |
option_one | |
option_one_commands | |
fi | |
################################################################### | |
# # | |
# OPTION_TWO # | |
# # | |
################################################################### | |
if [[ $userInput = 2 ]] | |
then | |
if [[ ${#TAB_ARRAY[@]} > 1 ]] | |
then | |
delete_tabs_check | |
fi | |
option_two | |
option_two_commands | |
fi | |
################################################################### | |
# # | |
# OPTION_THREE # | |
# # | |
################################################################### | |
if [[ $userInput = 3 ]] | |
then | |
if [[ ${#TAB_ARRAY[@]} > 1 ]] | |
then | |
delete_tabs_check | |
fi | |
option_three | |
fi | |
################################################################### | |
# # | |
# RESET TERMINAL TO 1 TAB CALLED MAIN # | |
# # | |
################################################################### | |
if [[ $userInput = "R" ]] | |
then | |
if [[ ${#TAB_ARRAY[@]} > 1 ]] | |
then | |
delete_tabs_check | |
fi | |
reset_terminal | |
fi | |
################################################################### | |
# # | |
# EXIT SCRIPT # | |
# # | |
################################################################### | |
if [[ $userInput = "Q" ]] | |
then | |
exit_script | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment