Search code examples
node.jsbashiterm2

Change terminal tab name when running a command on package.json


I have multiple apps that need to be run at the same time, but it's complicated keeping up with which one is which in the terminal. Is there a way that I can rename their respective tabs through the command on package.json?

The area with the scripts looks something like this right now:

{
  ...
  "scripts": {
     "app1:dev": "[SCRIPT_TO_NAME_TAB] && cd app1 && nodemon server",
     "app2:dev": "[SCRIPT_TO_NAME_TAB] && cd app2 && nodemon server",
     "app3:dev": "[SCRIPT_TO_NAME_TAB] && cd app3 && nodemon server",
  }
  ...
}

Is there anything I can replace on [SCRIPT_TO_NAME_TAB] with so that the tab is properly named whenever I run each of these scripts on my package.json? Thanks!

Edit: To add more to this I have found other threads that suggest I use something like

echo -n -e "\033]0;MY TITLE\007"

Unfortunately, that is not working and I get an error on the package.json file. So anyone know what is going on there?


Solution

  • This is a case that I ended up lacking some escape slash. So for me to get it to work, in package.json scripts I did the following:

    {
      ...
      "scripts": {
         "app1:dev": "echo -n -e \"\\033]0;MY TITLE\\007\" && cd app1 && nodemon server",
         ...
      }
      ...
    }