简体   繁体   English

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

[英]VSCode Integrated Terminal Doesn't Load .bashrc or .bash_profile

I have the following files to handle shell configuration:我有以下文件来处理 shell 配置:

#~/.bash_profile
if [ -f ~/.bashrc ]; then
   source ~/.bashrc
fi

and

#~/.bashrc
... configure shell

If I open VSCode from the command line using code , my .bashrc is loaded whenever I add a new instance of the integrated shell.如果我使用code从命令行打开 VSCode,每当我添加集成 shell 的新实例时,我的.bashrc就会被加载。

However if I open VSCode via its icon, only my .profile is loaded.但是,如果我通过其图标打开 VSCode,则只会加载我的.profile

How can I ensure my .bashrc is loaded instead?如何确保我的.bashrc被加载?

I've tried various settings for the terminal.integrated.shellArgs.osx setting without any luck.我已经尝试了terminal.integrated.shellArgs.osx设置的各种设置,但没有任何运气。

Simply add shell args to the settings.只需将 shell args 添加到设置中。 Tested on Windows with git bash but it should work same on Osx and Linux.使用 git bash 在 Windows 上进行了测试,但在 Osx 和 Linux 上应该可以正常工作。

In C:\\Users\\<username>\\AppData\\Roaming\\Code\\User\\settings.json or where your windows setting is: Add one of the following: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"],

just below "terminal.integrated.shell.<platform>...就在"terminal.integrated.shell.<platform>...

This will launch bash with the login argument.这将使用 login 参数启动 bash。

Another possible solution that just worked for me.另一个可能对我有用的解决方案。 The settings.json file (whcih you can access in File > Preferences > Settings > Features > terminal > Integrated > Automation Shell: Linux) had a parameter settings.json 文件(您可以在 File > Preferences > Settings > Features > terminal > Integrated > Automation Shell: Linux 中访问)有一个参数

    "terminal.integrated.inheritEnv": false

set to false by default.默认设置为false。 Changing it to true fixed the problem in my case.将其更改为 true 解决了我的问题。

I had the same problem with the Intellij Idea terminal on a Mac, the solution is the same for both.我在 Mac 上的 Intellij Idea 终端上遇到了同样的问题,两者的解决方案都是一样的。 In settings change the path to the integrated terminal to "/bin/bash".在设置中,将集成终端的路径更改为“/bin/bash”。 Hope that helps.希望有帮助。

在此处输入图片说明

You could also try the following:您还可以尝试以下操作:

1 Create a file named /usr/local/bin/bash-login and add : 1 创建一个名为 /usr/local/bin/bash-login 的文件并添加:

#!/bin/bash
bash -l

2 Run: 2 运行:

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

to make it executable.使其可执行。

3 On your VSC user settings add 3 在您的 VSC 用户设置中添加

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

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

Hope it helps希望能帮助到你

VSCode has deprecated "terminal.integrated.shellArgs.osx" in favor of using profiles. VSCode 已弃用"terminal.integrated.shellArgs.osx"以支持使用配置文件。 This does the trick for bash in osx.这对 osx 中的 bash 有用。 Omit the first line if you don't want bash to be your default profile:如果您不希望 bash 成为您的默认配置文件,请省略第一行:

  "terminal.integrated.defaultProfile.osx": "bash",
  "terminal.integrated.profiles.osx": {
    "bash": {
      "path": "bash",
      "args": ["-l"]
    }
  }

"terminal.integrated.shellArgs.osx": ["-l"] is deprecated. "terminal.integrated.shellArgs.osx": ["-l"]已弃用。

I personally wanted to use .bash_profile , so I made a .bashrc with this:我个人想使用.bash_profile ,所以我用这个制作了一个.bashrc

if [ -f ~/.bashrc ]; then
   source ~/.bash_profile
fi

And then I had to do a full computer restart (just restarting VS code didn't work).然后我不得不重新启动完整的计算机(只是重新启动 VS 代码不起作用)。

Bash will load various DotFiles sequentially: Bash 将依次加载各种 DotFiles:

  1. ~/.bash_profile
  2. ~/.bash_login
  3. ~/.profile

If ~/.bash_profile been loaded, the second and third one will not be loaded.如果加载了~/.bash_profile ,则不会加载第二个和第三个。

If ~/.bash_profile is not loaded, bash will find second one.如果~/.bash_profile没有加载,bash 会找到第二个。 If ~/.bash_login been loaded, the third one will not be loaded.如果加载了~/.bash_login ,则不会加载第三个。

If ~/.bash_profile and ~/.bash_login are both not loaded, Bash will try to load ~/.profile file.如果~/.bash_profile~/.bash_login都没有加载,Bash 将尝试加载~/.profile文件。

A fresh Ubuntu installation will only contains ~/.profile file.全新的 Ubuntu 安装将仅包含~/.profile文件。 So I think it will be better NOT to use the ~/.bash_profile to avoid issues happening.所以我认为最好不要使用~/.bash_profile来避免发生问题。 Just use the ~/.profile file.只需使用~/.profile文件。 Then your VSCode won't need to config anything.然后你的 VSCode 将不需要配置任何东西。

I was having this issue too.我也有这个问题。 But in my case I was on windows with Visual Studio code opening a remote dev env inside my CentOS WSL.但就我而言,我在 windows 上使用 Visual Studio 代码在我的 CentOS WSL 中打开一个远程开发环境。

So fixing the configuration of this use case was a bit different.因此修复这个用例的配置有点不同。 In the IDE open settings.在IDE打开设置。 Then at the top select "Remote [WSL: XXX]"然后在顶部 select “Remote [WSL: XXX]”

在此处输入图像描述

The scroll down to Integrated -> Profiles: Linux And click edit in settings.json向下滚动到 Integrated -> Profiles: Linux 然后点击 settings.json 中的编辑在此处输入图像描述

Then I added the following to the file:然后我将以下内容添加到文件中:

"terminal.integrated.defaultProfile.linux": "bash",
"terminal.integrated.profiles.linux": {
    "bash": {
      "path": "bash",
      "args": ["-l"]
    }
  }

Save the settings file and the next terminal you open will respect your ~/.bash_profile.保存设置文件,您打开的下一个终端将遵循您的 ~/.bash_profile。 NOTE: my ~/.bash_profile had the same lines that someone else recommended adding to load the bashrc file in it already.注意:我的 ~/.bash_profile 与其他人建议添加的行相同,以加载 bashrc 文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM