Jese Leos

First Schripts First

$cripts

Bash Scripts to Initiate Local Development Sessions

Working on full stack projects, I usually use Strapi CMS as a backend and Nuxt for frontend,  and a common situation is to want to quickly open VS Code for both projects and run npm commands to start,

I use bash and open the CMS project first and run npm run develop
then open the Nuxt project and run npx nuxi cleanup && npx nuxi dev .

Having two VS Code projects open, switching context using alt+tab becomes messy, so to hint to myself for quick switching, I changed the bash terminal background to purple for Strapi and green for Nuxt.

To simplify the process, I use the bash scripts below:

On the desktop I create two files myapp-frontend.sh & myapp-backend.sh  where .sh is the extension for shell scripts.

Commands

Every script must start with a hash bang slash bin slash bash 🎶

#!/bin/bash

  • ls: list available files
  • cd: change directory to file location
  • sleep: do nothing for n seconds
  • pwd: print working directory to see where you are
  • git branch: to write which branch is active
  • echo -ne '\e]11;#3F0046\e\\'  is to modify the bash terminal background to the hex color

Frontend Nuxt Script

#!/bin/bash

cd /c/code/project/folder
pwd
echo -ne '\e]11;#003736\e\\'
git branch
npm run dev

Backend Strapi CMS

#!/bin/bash

echo -ne '\e]11;#3F0046\e\\'
cd /d/my/project/folder
pwd

git branch

npm run develop

A path with spaces will break the script and must be escaped

Sudden Crash After NPM scripts:

A crash error will close the window, common when the default port is already in use, and it closes so fast you might not be able to read the logs,
To kill a port on ubuntu use the command

npx kill-port ####



Built With

Nuxt.js

© 2019-2023 Khalid Zamer