I'm pretty sure you can do this using the terminal.integrated.cwd
setting. You can set it in your user settings.json
file or your workspace's .vscode/settings.json
file.
It supports variable substitution. See the list of available variables here: https://code.visualstudio.com/docs/editor/variables-reference#_predefined-variables.
Some examples of variables you can use: ${workspaceFolder}
, ${fileWorkspaceFolder}
, ${fileDirname}
, ${selectedText}
.
It seems that not all the directory variables are supported. For example, userHome
doesn't work for me on my machine.
See also the terminal.integrated.splitCwd
setting.
You may also be interested in the workbench.action.terminal.newInActiveWorkspace
keybinding command.
If the terminal is opened for a task, then use the task's options
property object's cwd
property (docs).