Visual studio code VSCode:在WSL终端打开时自动执行命令

Visual studio code VSCode:在WSL终端打开时自动执行命令,visual-studio-code,windows-subsystem-for-linux,Visual Studio Code,Windows Subsystem For Linux,我想在每次打开VisualStudio代码(Windows10)上的WSL终端时自动执行一个命令 我没有使用远程WSL扩展,只是使用具有以下设置的WSL终端: “terminal.integrated.shell.windows”:“C:\\windows\\System32\\wsl.exe” 我尝试使用terminal.integrated.shellArgs.windows设置失败 有办法吗?您可以在settings.json中输入: { "terminal.integr

我想在每次打开VisualStudio代码(Windows10)上的WSL终端时自动执行一个命令

我没有使用远程WSL扩展,只是使用具有以下设置的WSL终端:
“terminal.integrated.shell.windows”:“C:\\windows\\System32\\wsl.exe”

我尝试使用
terminal.integrated.shellArgs.windows
设置失败


有办法吗?

您可以在settings.json中输入:

{
    "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\wsl.exe",
    "terminal.integrated.shellArgs.windows": [
        "-e",
        "bash",
        "--rcfile",
        "/path/to/vscode.bashrc"
    ]
}
在vscode.bashrc中

source $HOME/.bashrc
your-command
settings.json中的内容要求vscode运行以下命令:

"C:\WINDOWS\System32\wsl.exe" -e bash --rcfile /path/to/vscode.bashrc
wsl的选项运行“bash--rcfile/path/to/vscode.bashrc”

--rcfile
用于bash运行/path/to/vscode.bashrc而不是$HOME/.bashrc


有关详细信息,请参见

终端启动外壳。如果是bash,可以将命令放在~/.bashrc或~/.bash中_profile@Philippe我不希望每次打开终端时都执行此命令,而只是在VSCode中执行此命令,因此,如果可能的话,使用VSCode设置VSCode_GIT_ASKPASS_节点似乎没有在VSCode终端中设置:您能给我一个如何实现这一点的示例吗?您是否尝试过
terminal.integrated.shellArgs.linux
?@x00是的,我尝试过,但没有成功哇,它工作得很好,谢谢。你能简单解释一下这些论点的作用吗?或者你能推荐一个资源来解释它吗?