0

I find myself in a position where it would be useful to open a VS Code terminal profile and have it automatically run certain commands.

The specific case is I want to set up a profile where it automatically ssh's into another machine. I am doing this because I do my dev work on one machine (machine_A), but the actual running of the code occurs on a second machine (machine_B). Is it possible to make a profile that automatically runs

ssh {user_name}@{machine_name}

upon opening the profile?

Machine_A and machine_B are both remote and being accessed through RemoteSSH. (And no I cannot do the dev work on the same machine I run the code.)

I am currently defining a custom profile in the workspace settings file ({workspace}/.vscode/settings.json) as suggested by the VS Code docs on terminal profiles. My current attempt is:

{
    "terminal.integrated.profiles.windows": {
        "ssh_session": {
            "path": "ssh",
            "args": \["{user_name}@{machine_name}"\]
        }
    }
}
starball
  • 20,030
  • 7
  • 43
  • 238
Noddy
  • 1

1 Answers1

0

I'd instead try to start a specific shell, and then use shell-specific mechanisms to run those commands. Your shell might have a mechanism to take commands from the commandline (Ex. Bash -c), or to take commands from a startup/profile file from a file at a specific, fixed location(s) or a customizable location specified in the commandline. If from a file at a fixed location such as a Bash profile / bashrc file, you can scope any general VS Code-specific workflow stuff to go inside a control flow block conditioned upon environment variables like TERM_PROGRAM being set to vscode. If you want to run commands on the remote side of the SSH connection, consult your SSH client's documentation. OpenSSH, for example, has a command parameter for specifying a command to run on the remote side.

starball
  • 20,030
  • 7
  • 43
  • 238