
Bash Scripts To Start Work
Today I automated the “setup to start working” for one of my projects. It is a site that uses an API, and every time I wanted to start working on it I had to open the two projects independently, open the browser, and run the two projects. I created a bash script that manages opening everything, and another one to close it all. This lets me fully focus on the code and start quickly with a simple double click.
Script for opening everything:
#!/bin/bash
API_DIR="/path/to/api/project/dir"
SITE_DIR="/path/to/site/project/dir"
# opening the API in vscode and running the the API in a new terminal
code "$API_DIR"
gnome-terminal --working-directory="$API_DIR" -- bash -c "
source '$API_DIR/.venv/bin/activate';
python '$API_DIR/main.py';
exec bash
"
# opening the Site in vscode,running the Site in a new terminal, and opening it in firefox
code "$SITE_DIR"
gnome-terminal --working-directory="$SITE_DIR" -- bash -c "
docker start containername -i;
exec bash
"
sleep 5 # waiting for 5 seconds untill the site is running
firefox http://0.0.0.0:8080/
Script for closing it all:
#!/bin/bash
# Close all VS Code instances
pkill -f "code"
# Close all terminal windows
pkill -f "gnome-terminal"
As many other scripts, I saved these two in my code snippets repository.