I have a monorepo, and every time I open a terminal, I have to cd
to a specific directory; and it’s different for each terminal.
I want to skip this step and set different default directories for terminals in vscode.
Something like terminal.integrated.cwd
, but per profile:
"terminal.integrated.profiles.windows": {
"My Frontend": {
"source": "PowerShell"
"cwd": "frontend-folder"
},
"My Backend": {
"path": "C:\Windows\System32\wsl.exe",
"cwd": "backend-folder"
}
}
However, this setting doesn’t exist and I can only set one cwd
for all.
Ideally, I want powershell (default terminal) to open in /frontend-folder and Ubuntu (WSL) terminal to open in /backend-folder.
Update
This setting works for powershell
{
...
"My Frontend": {
"source": "PowerShell",
"icon": "terminal-powershell",
"args": [
"-NoExit",
"-Command",
"Set-Location -Path '${workspaceFolder}/frontend-folder'"
]
}
...
}
But I don’t know what is the equivalent for WSL.
This setting works for powershell
For robustness, use embedded double-quoting around the path, so as to also support paths with embedded '
characters:
"Set-Location -Path "${workspaceFolder}/frontend-folder""
But I don’t know what is the equivalent for WSL.
Use wsl.exe
‘s --cd
parameter to pass the startup directory; run wsl --help
to see all supported parameters and their descriptions.
To put it all together:
"terminal.integrated.profiles.windows": {
// ...
"My Frontend": {
"source": "PowerShell",
"args": [
"-NoExit",
"-Command",
"Set-Location -Path "${workspaceFolder}\frontend-folder""
]
},
"My Backend": {
"path": "C:\Windows\System32\wsl.exe",
"args": [ "--cd", "${workspaceFolder}\backend-folder" ]
}
// ...
}