68

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
  • 42,754
  • 56
  • 195
  • 331
  • 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

9 Answers9

51

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
  • 780
  • 7
  • 19
Jose Ananio
  • 666
  • 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
  • 10
    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
47

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,947
  • 4
  • 27
  • 22
  • For other people reference, it works well for me without having to change any terminal related options in Preference -> Settings in the GUI. My VS Code version `1.74.2`. – Richard Jan 04 '23 at 10:35
  • Thanks! This did not quite work for me, I am getting a login shell, but it is batch (`ENVIRONMENT=BATCH`). I still need to figure out how to get `ENVIRONMENT=INTERACTIVE` by default. – Walter Nissen Mar 02 '23 at 23:28
27

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
  • 419
  • 5
  • 7
  • Gosh, I was searching forever to find this. Thank you! – Niki Mar 08 '21 at 07:55
  • 2
    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
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
  • 351
  • 3
  • 6
8

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
  • 505
  • 2
  • 9
6

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.

So fixing the configuration of this use case was a bit different. In the IDE open settings. Then at the top select "Remote [WSL: XXX]"

enter image description here

The scroll down to Integrated -> Profiles: Linux And click edit in settings.json enter image description here

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. NOTE: my ~/.bash_profile had the same lines that someone else recommended adding to load the bashrc file in it already.

KrisTC
  • 551
  • 5
  • 5
  • Also incase it is usefult for people. The path of the settings file on the WSL file system is: ```/root/.vscode-server/data/Machine/settings.json``` – KrisTC Nov 28 '22 at 15:54
  • For first time WSL terminal is opened, this setting ignored. The deprecated setting worked through `"terminal.integrated.shellArgs.linux": ["-l"]` Credit: https://github.com/microsoft/vscode-remote-release/issues/6096#issuecomment-1506941761 – Joshua Graham Apr 26 '23 at 01:48
2

"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
  • 4,620
  • 6
  • 41
  • 75
  • 1
    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
  • 1
    Strangely, this worked for me without rebooting or reloading vscode – DiegoSalazar Dec 09 '22 at 19:24
2

Bash will load various DotFiles sequentially:

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

If ~/.bash_profile been loaded, the second and third one will not be loaded.

If ~/.bash_profile is not loaded, bash will find second one. If ~/.bash_login been loaded, the third one will not be loaded.

If ~/.bash_profile and ~/.bash_login are both not loaded, Bash will try to load ~/.profile file.

A fresh Ubuntu installation will only contains ~/.profile file. So I think it will be better NOT to use the ~/.bash_profile to avoid issues happening. Just use the ~/.profile file. Then your VSCode won't need to config anything.

Will Huang
  • 2,955
  • 2
  • 37
  • 90
0

I see a lot of people recommending the -l parameter to bash but that didn't work for me. Instead use the -i parameter (interactive). This goes in your user settings file. This is for Mac OS. If on a different platform change osx to either linux or windows.

  "terminal.integrated.profiles.osx": {
        "bash": {
          "path": "bash",
          "args": ["-i"]
        }
    }
Michael
  • 2,683
  • 28
  • 30