Most build tools support doing so via some variation of a
--port command line parameter. You can add parameters to your npm command by adding a double dash
npm run dev would become
npm run dev -- -p 8080.
For docker, you can override the relevant configurations.
If you can’t do that, it’s not the end of the world. You could build yourself helpers to quickly close the other projects you have open. For docker you could use
docker ps -aq | xargs docker stop to stop all running containers, for desktop applications you can send a shutdown command via
osascript -e 'quit app "Visual Studio Code"'. If that doesn’t work for some reason, you have the (somewhat dangerous) possibility of using
I suggest doing this setup one by one, the next time you open each project’s workspace. Take note what programs you need to open and which commands you need to run, chain them, and put them in a shell alias or bash file.
For my blog, this alias is really simple. My
.zshrc file contains an entry for a
alias goblog='cd /Users/reneroth/projects/reneroth.xyz-jekyll-blog && code . && npm run dev -- -o'
It opens the project folder, open Visual Studio Code, and runs the npm command needed to build and serve the project. The
-o parameter gets passed through and automatically opens the browser.
For bigger projects, the script can get more detailed:
docker ps -aq | xargs docker stop # stop all runnnig docker containers open -a "Sequel Ace" # open database client cd ~/customer/project/backend # open backend folder code . # open backend in VS Code docker-compose up -d # bring up backend containers open -a "Google Chrome" http://backend.test/ # open the backend in the browser cd ../frontend # open frontend folder code . # open frontend in VS Code npm run dev -- -o # run frontend pipeline, opening the browser
If your project is one of those behemoths where you need more than one terminal open and running at the same time, all those techniques can be combined with any scripting capabilities your terminal offers. For iTerm2, I use the neat iterm-workspace script in combination with the techniques mentioned here.