Skip to content

Commit

Permalink
feat: add start_local_env.sh script.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
saku-koodari committed Sep 17, 2024
1 parent 48c3e59 commit 78bb6d8
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions scripts/start_local_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/sh

# remember to chmod +x start_local_env.sh
kotorekisteri_start_tmux() {
SESS_NAME=kotorekisteri
PANE1=kotorekisteri
REPO_ROOT=${1:-'.'}

(
cd $REPO_ROOT

# Install dependencies
echo "Installing dependencies..."
mise install

# Use old session if exists
tmux has-session -t $SESS_NAME 2>/dev/null
if [ $? -eq 0 ]; then
tmux attach -t $SESS_NAME
# TODO: Instead of return, kill the old session.
return
fi

# If there is no session...
# Start a new tmux session and detach immediately
# Window 0:zsh
echo "Starting new tmux session..."
tmux new-session -d -s $SESS_NAME

# Window 0:database
WINDOW="database"
# database: left pane (docker running)
tmux rename-window -t $SESS_NAME:0 "$WINDOW"
tmux send-keys -t $SESS_NAME:"$WINDOW.0" "open -a \"Docker\"" C-m
tmux send-keys -t $SESS_NAME:"$WINDOW.0" "docker compose up" C-m

# database: right pane (flyway migrate)
tmux split-window -h -t $SESSION:"$WINDOW"
tmux send-keys -t $SESS_NAME:"$WINDOW.1" "(cd server &&
sleep 5 && echo \"10 seconds left to run migrations...\" &&
sleep 5 && echo \"05 seconds left to run migrations...\" &&
./mvnw flyway:migrate)" C-m

# Window 1:idea
WINDOW="idea"
tmux new-window -t $SESS_NAME -n "idea"
tmux send-keys -t $SESS_NAME:"idea" "idea ." C-m

# Window 2:springboot
WINDOW="springboot"
tmux new-window -t $SESS_NAME -n "$WINDOW"
tmux send-keys -t $SESS_NAME:"$WINDOW" "cd server && sleep 5" C-m
tmux send-keys -t $SESS_NAME:"$WINDOW" "mvn clean install" C-m
tmux send-keys -t $SESS_NAME:"$WINDOW" "mvn package" C-m
tmux send-keys -t $SESS_NAME:"$WINDOW" "./mvnw spring-boot:run" C-m

# Window 3:workspace
WINDOW="workspace"
tmux new-window -t $SESS_NAME -n "$WINDOW"
tmux send-keys -t $SESS_NAME:"$WINDOW" "git log --oneline --decorate=full --graph --all --oneline" C-m
tmux split-window -h -t $SESSION:"$WINDOW"
tmux send-keys -t $SESS_NAME:"$WINDOW.1" "ls -la" C-m
tmux send-keys -t $SESS_NAME:"$WINDOW.1" "git status" C-m

tmux attach
)
}

kotorekisteri_start_tmux $1

0 comments on commit 78bb6d8

Please sign in to comment.