DEV Community

Cover image for One script, one window, multiple attached commands
Alish Giri
Alish Giri

Posted on

One script, one window, multiple attached commands

Every time I started working on a project I had open up two to three different Terminal windows to start development work 🙄.

One to start the Docker, other to start the server and finally one more to run the frontend. And viewing logs on all these terminal one after the other was also getting annoying so I did some research and found something incredible 🚀.

You can create one script and chain different commands using & to run multiple attached sessions as shown below.

# package.json file

{
    ...
    scripts: {
        ...
        "run:dev": "docker-compose up & (cd path/to/server && ./run/server) & yarn start"
    }
}
Enter fullscreen mode Exit fullscreen mode

The benefits of using this is just out of this world. You will be using one terminal window to view logs from multiple different projects.

And to kill the previous processes in the chain use the following syntax. Ctrl + C will only close the later one.

 # To list all the running processes. Explore how the name works.
ps aux | grep <app_name>

pkill <app_name> # For MacOS & Linux

taskkill -f -im mac-server # For Windows
Enter fullscreen mode Exit fullscreen mode

Top comments (0)