VSCode集成终端不加载.bashrc或.bash_profile

Und*_*ion 8 bash shell settings visual-studio-code

我有以下文件来处理外壳程序配置:

#~/.bash_profile
if [ -f ~/.bashrc ]; then
   source ~/.bashrc
fi
Run Code Online (Sandbox Code Playgroud)

#~/.bashrc
... configure shell
Run Code Online (Sandbox Code Playgroud)

如果使用来从命令行打开VSCode code.bashrc则每当我添加集成shell的新实例时都会加载my 。

但是,如果我通过其图标打开VSCode,则仅.profile加载我的代码。

如何确保我.bashrc已加载?

我尝试了各种设置,但terminal.integrated.shellArgs.osx没有运气。

aha*_*rat 56

VSCode 已弃用"terminal.integrated.shellArgs.osx",转而使用配置文件(将(aka ) 参数传递-l--login"args"给)。这对 osx 中的 bash 起到了作用。如果您不希望 bash 成为默认配置文件,请省略第一行:

  "terminal.integrated.defaultProfile.osx": "bash",
  "terminal.integrated.profiles.osx": {
    "bash": {
      "path": "bash",
      "args": ["-l"]
    }
  }
Run Code Online (Sandbox Code Playgroud)

Windows 的类似方法:

"terminal.integrated.defaultProfile.windows": "Git Bash",
"terminal.integrated.profiles.windows": {
    "Git Bash": {
      "path": [ "C:\\Program Files\\Git\\bin\\bash.exe" ],
      # --login is same as -l
      "args": [ "--login" ]
    }
}
Run Code Online (Sandbox Code Playgroud)


小智 15

另一个可能对我有用的解决方案。settings.json 文件(您可以在 File > Preferences > Settings > Features > terminal > Integrated > Automation Shell: Linux 中访问)有一个参数

    "terminal.integrated.inheritEnv": false
Run Code Online (Sandbox Code Playgroud)

默认设置为false。将其更改为 true 解决了我的问题。

  • 这也给了我所需要的提示。实际上,现在`terminal.integrated.inheritEnv`的默认值似乎是`true`,请参阅https://code.visualstudio.com/updates/v1_57#_improved-launching-with-clean-environment (3认同)

小智 10

我在 Mac 上的 Intellij Idea 终端上遇到了同样的问题,两者的解决方案都是一样的。在设置中,将集成终端的路径更改为“/bin/bash”。希望有帮助。

在此处输入图片说明


小智 9

我也遇到了这个问题。但就我而言,我在 Windows 上使用 Visual Studio 代码在我的 CentOS WSL 中打开远程开发环境。

因此修复这个用例的配置有点不同。在IDE中打开设置。然后在顶部选择“远程 [WSL: XXX]”

在此输入图像描述

向下滚动到 Integrated -> Profiles: Linux 然后单击 settings.json 中的编辑 在此输入图像描述

然后我将以下内容添加到文件中:

"terminal.integrated.defaultProfile.linux": "bash",
"terminal.integrated.profiles.linux": {
    "bash": {
      "path": "bash",
      "args": ["-l"]
    }
  }
Run Code Online (Sandbox Code Playgroud)

保存设置文件,您打开的下一个终端将尊重您的 ~/.bash_profile。注意:我的 ~/.bash_profile 具有与其他人建议添加的相同行以加载 bashrc 文件。


cur*_*d3r 6

您还可以尝试以下操作:

1 创建一个名为 /usr/local/bin/bash-login 的文件并添加:

#!/bin/bash
bash -l
Run Code Online (Sandbox Code Playgroud)

2 运行:

chmod +x /usr/local/bin/bash-login 
Run Code Online (Sandbox Code Playgroud)

使其可执行。

3 在您的 VSC 用户设置中添加

   { "terminal.integrated.shell.osx": "/usr/local/bin/bash-login" }
Run Code Online (Sandbox Code Playgroud)

该解决方案在https://github.com/Microsoft/vscode/issues/7263 中进行了描述。

希望能帮助到你


小智 6

只需将shell参数添加到设置中。在Windows上使用git bash进行了测试,但是在Osx和Linux上应该可以正常使用。

C:\Users\<username>\AppData\Roaming\Code\User\settings.json或在您的Windows设置是:添加以下之一:

"terminal.integrated.shellArgs.windows": ["-l"],

"terminal.integrated.shellArgs.linux": ["-l"],

"terminal.integrated.shellArgs.osx": ["-l"],
Run Code Online (Sandbox Code Playgroud)

略低于 "terminal.integrated.shell.<platform>...

这将使用登录参数启动bash。

  • VSCode 已弃用“terminal.integrated.shellArgs.osx”,转而使用配置文件。我建议访客看看我下面的回答。 (12认同)