Search code examples
visual-studio-codeterminalconfigurationmacrosconsole

How to create a "terminal configuration macro" in VS Code? Open and split multiple terminals easily


~400 times by year 1 :

  • open VS Code
  • open one terminal
  • divide the terminal into 2 parts
  • run "npm run hot" (first split)
  • leave the other split terminal empty
  • open a second terminal (with "+" button)
  • split it into 3 parts
  • run "php artisan websockets:serve" (first part)
  • run "php artisan queue:words" (second part)
  • run "maidev --ip=localhost" (third part)
  • and finally I can start to work

I'm sure I am not alone with this problem. Would anyone have a method to optimize that with one command or configuration ?

Thanks for your help !


Solution

  • Okay, a day after answering this with other two answers, I saw this extension: Restore Terminals at this other question https://stackoverflow.com/a/62595681/836330

    This extension seems to work quite well. Put this into your settings.json:

      "restoreTerminals.runOnStartup": false,   // true is the default
              // set to false if using a keybinding or the command palette
    
      "restoreTerminals.terminals": [
        {
          "splitTerminals": [
            {
              "name": "server",
              "commands": [
                "npm run test"
              ]
            },
            {
              "name": "empty",
            }
          ]
        },
        {
          "splitTerminals": [
            {
              "name": "websockets",
              "commands": [
                "ls -l"
              ]
            },
            {
              "name": "queue",
              "commands": [
                "cd zip",
                "gulp sass"
              ]
            },
            {
              "name": "maidev",
              "commands": [
                "cd zip-multiple",
                "gulp"
              ]
            }
          ]
        }
      ],
    

    And a keybinding:

    {
      "key": "shift+alt+t",    // whatever keybinding if you wish
      "command": "restore-terminals.restoreTerminals",
    },
    

    If on Windows, I would still use the setting:

     "terminal.integrated.windowsEnableConpty": false
    

    as the same issue occurs when using this extension as any other method to open and write to terminals quickly - if you then try to close the terminals vscode will hang and eventually timeout and need to be reopened.