11

As the title suggest, when I start my git bash regularly it loads my ~/.bash_profile but the one integrated in my VS Code is not loading it.

Where can I put .bash_profile so that it would also load in VS Code?

Edit: here's my vs code with the terminal vs code

and here's my git bash git bash

I want to load the same .bash_profile file in my vs code terminal that is loading on my git bash, so that it would show the branch name and also have aliases i defined there.

4
  • What file are you talking about? Commented May 15, 2017 at 14:38
  • my .bash_profile that is currently at ~/.bash_prifile Commented May 15, 2017 at 14:46
  • Are you asking how to integrate your git bash profile with Visual Studio? Commented May 15, 2017 at 14:55
  • Please see edit Commented May 15, 2017 at 15:06

7 Answers 7

9

Turns out, that it had to do in how the terminal is started. The git bash one (in its own window) is using the login to start and hence reads .bash_profile.

The one in vs code is started not in the login way (sorry, I'm not well versed in this), and reads .bashrc instead of .bash_profile.

My solution was to move all the stuff I kept in .bash_profile and move it to .bashrc and add the following line to .bash_profile:

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

which loads the .bashrc contents when starting in the login way.

1
  • git bash for windows does the same thing with a similar syntax test -f ~/.bashrc && . ~/.bashrc Commented May 8, 2020 at 18:18
5

You can try adding to the settings: "terminal.integrated.shellArgs.windows": ["-l"],


As an alternative you can use the .bashrc file instead of .bash_profile.

1
  • VS Code says this now: This is deprecated, the new recommended way to configure your default shell is by creating a terminal profile in #terminal.integrated.profiles.linux# and setting its profile name as the default in #terminal.integrated.defaultProfile.linux#. See code.visualstudio.com/docs/editor/… Commented Jan 14, 2022 at 17:46
2

Using WSL (Ubuntu 16.04), I had to add the following option to my settings.json in VS Code in order to run the shell as a login shell:

"terminal.integrated.shellArgs.linux": ["-l"]
0
2

To everybody suggesting using .bashrc as a replacement for .bash_profile, it's important to distinguish between the two, as they are different:

  • .bash_profile is executed at login.
  • .bashrc is executed each time a bash instance is created, including sub-shells.

Using .bashrc for such settings might cause errors and even be dangerous. For instance, this kind of code is usually added to .bash_profile and should never be added to .bashrc:

PATH="$PATH:$HOME/bin"

(The HOME variable could have been altered, plus $HOME/bin will be added multiple times).

Also, aliases are defined in .bashrc (like alias rm='/usr/bin/rm -i') and are only meant to be used in interactive shells, so scripts using rm or cp will break.

The right answer for this question, as others suggested, is adding:

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

The local file can be found here:

C:\Users\{username}\AppData\Roaming\Code\User\settings.json

That will make shell scripts started from VSCode to run the .bash_profile script, but not the subshells.

1

An alternative method to the accepted answer:

In your root directory add a file .bashrc with the following code:

source <rootdirectory>/.bash_profile

Where you replace with your own root.

For example that could be C:/Users/domkj/.bash_profile

0

I created .bashrc in home path and importing that other profiles test -f ~/.bashrc && . ~/.bashrc

0

Windows/WSL users, in the VSCode settings.json file I added "-l" to the "args" property which is now listed under terminal.integrated.profiles.linux/bash:

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

The local file can be found here:

C:\Users\{username}\AppData\Roaming\Code\User\settings.json

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.