visual-studio-code

Open terminal before running sendSequence in vscode


I have a shortcut with this command

 {
    "key": "ctrl+r",
    "when": "terminalFocus",
    "command": "workbench.action.terminal.sendSequence",
    "args": {
      "text": #command#
    }
 },

And before running it I want to open a integrated terminal window and then send the sequence and run the code - and keep the terminal open afterwards, the shortcut should also not open a terminal if one is already running. Would this be possible?


Solution

  • You will need a macro extension to run two commands: getting the terminal and writing to it. Using the extension multi-command try this keybinding:

    {
      "key": "alt+q",
      "command": "extension.multiCommand.execute",
      "args": {
        "sequence": [
          "workbench.action.terminal.focus",
          {
            "command": "workbench.action.terminal.sendSequence",
            "args": {
              "text": "${fileBasename}"
            }
          }
        ]
      }
    }
    

    If you do not have a terminal open, it should open one and focus it. If you do have a terminal open it should focus that terminal.