关于bash:VSCode集成终端不加载.bashrc或.bash_profile

VSCode Integrated Terminal Doesn't Load .bashrc or .bash_profile

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

1
2
3
4
#~/.bash_profile
if [ -f ~/.bashrc ]; then
   source ~/.bashrc
fi

1
2
#~/.bashrc
... configure shell

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

但是,如果我通过VSCode图标打开VSCode,则只会加载我的.profile

如何确保我的.bashrc已加载?

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


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

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

1
2
3
4
5
"terminal.integrated.shellArgs.windows": ["-l"],

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

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

正好在"terminal.integrated.shell.<platform>...

之下

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


另一个对我有用的可能解决方案。 settings.json文件(您可以在"文件">"首选项">"设置">"功能">"终端">"集成">"自动化外壳:Linux"中访问)具有参数

1
   "terminal.integrated.inheritEnv": false

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


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

enter

1
2
#!/bin/bash
bash -l

2运行:

1
chmod +x /usr/local/bin/bash-login

使其可执行。

3在VSC用户设置上,添加

1
   {"terminal.integrated.shell.osx":"/usr/local/bin/bash-login" }

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

希望对您有所帮助