45

I have the following files to handle shell configuration:

#~/.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.

However if I open VSCode via its icon, only my .profile is loaded.

How can I ensure my .bashrc is loaded instead?

I've tried various settings for the terminal.integrated.shellArgs.osx setting without any luck.

Undistraction
  • 40,783
  • 52
  • 179
  • 315
  • I was having a problem that it was loading bash_profile instead of bashrc. Deleting the bash_profile file fixed it. – madprops Mar 19 '19 at 17:36

6 Answers6

49

Simply add shell arguments to the VsCode settings.json file.

Paths to the settings.json file are as follows:

Windows: C:\Users\<username>\AppData\Roaming\Code\User\settings.json`

Linux:   $HOME/.config/Code/User/settings.json

Mac:     $HOME/Library/Application\ Support/Code/User/settings.json

Add one of the following:

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

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

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

This will launch your shell of choice with the login argument. This will thus execute any user profile that is setup.

Miles
  • 706
  • 6
  • 15
Jose Ananio
  • 614
  • 6
  • 5
  • These brackets around `["-l"]` are missing when you use the command palette to access this file and insert this setting. When I added the brackets it worked for me, now osx zsh shell is loading my usual environment. – Merlin Nov 06 '20 at 20:39
  • To get this to also start in the workspace directory I added this to the end of my `~/.bash_profile` : `[[ -n "${VSCODE_IPC_HOOK_CLI}" ]] && cd "${OLDPWD}" ` – aizimmer Sep 20 '21 at 13:29
  • 6
    VSCode has deprecated `"terminal.integrated.shellArgs.osx"` in favor of using profiles. I recommend visitors take a look at my answer below. – ahaurat Oct 08 '21 at 15:49
21

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

    "terminal.integrated.inheritEnv": false

set to false by default. Changing it to true fixed the problem in my case.

user3091644
  • 361
  • 3
  • 7
  • Gosh, I was searching forever to find this. Thank you! – Niki Mar 08 '21 at 07:55
  • This also gave me the needed hint. Actually it seems that now the default of `terminal.integrated.inheritEnv` is `true`, see https://code.visualstudio.com/updates/v1_57#_improved-launching-with-clean-environment – MarcusS Aug 30 '21 at 08:08
21

VSCode has deprecated "terminal.integrated.shellArgs.osx" in favor of using profiles. This does the trick for bash in osx. Omit the first line if you don't want bash to be your default profile:

  "terminal.integrated.defaultProfile.osx": "bash",
  "terminal.integrated.profiles.osx": {
    "bash": {
      "path": "bash",
      "args": ["-l"]
    }
  }
ahaurat
  • 3,537
  • 3
  • 23
  • 21
11

I had the same problem with the Intellij Idea terminal on a Mac, the solution is the same for both. In settings change the path to the integrated terminal to "/bin/bash". Hope that helps.

enter image description here

Tony Ly
  • 321
  • 3
  • 6
6

You could also try the following:

1 Create a file named /usr/local/bin/bash-login and add :

#!/bin/bash
bash -l

2 Run:

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

to make it executable.

3 On your VSC user settings add

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

The solution was described at https://github.com/Microsoft/vscode/issues/7263.

Hope it helps

curi0uz_k0d3r
  • 455
  • 2
  • 9
1

"terminal.integrated.shellArgs.osx": ["-l"] is deprecated.

I personally wanted to use .bash_profile, so I made a .bashrc with this:

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).

Kevin Danikowski
  • 3,470
  • 4
  • 27
  • 59
  • should that first line maybe be `if [ -f ~/.bash_profile ]; then`? It doesn't really make sense to test for the existence of a file from within that same file – tel Aug 10 '21 at 23:29
  • @tel good point, Hard to say, I just know that this worked for me. – Kevin Danikowski Aug 12 '21 at 14:02
  • 1
    +1 for mentioning full computer restart. Nothing was working for me and then this did. I would love to know why this works when logging out and logging in again doesn't. – nschmeller Aug 16 '21 at 18:42