Skip to content

do not always launch integrated terminal's shell as a login shell #50340

Closed

Description

On macOS VS Code's integrated terminal by default uses bash with a -l option which means:

Make bash act as if it had been invoked as a login shell

This means that bash for a newly created integrated terminal will always try to read ~/.bash_profile, ~/.bash_login, and ~/.profile.

IMO passing -l is a bad idea for (at least) the following reasons:

  • if VS Code is launched from a terminal where the user has set specific environment variables, VS Code tries hard to preserve these environment variables for the workspace so that a subsequent integrated terminal (or task or debug session) inherits these environment variables. By using the -l option this effort is negated because bash reads ~/.bash_profile, ~/.bash_login, and ~/.profile which might reset the carefully established environment.

  • if a different shell is configured via the terminal.integrated.shell.osx (e.g. PowerShell), the user is not aware that the -l is passed and PowerShell fails with a strange error message.

Ideally -l should only be used if VS Code was not launched from a terminal (because that would be more in line with how Terminal.app or iTerm.app behave on macOS).

This might require a new settings attribute loginShellArgs that is only used if the shell is started as a login-shell. However, this does not address the second problem from above.

/cc Dirk Bäumer (@dbaeumer) João Moreno (@joaomoreno)

Activity

  1. added
    bug
    on May 23, 2018
  2. Tyriar commented on May 23, 2018

    @Tyriar
    Contributor

    This is a tricky subject and I frequently still get issues reported around this. A common one is this which is caused by running a login shell from within a login shell (due to the way we get the environment when not launched from a terminal:

    https://code.visualstudio.com/docs/editor/integrated-terminal#_why-is-nvm-complaining-about-a-prefix-option-when-the-integrated-terminal-is-launched

    You can repro the problem in external terminals by running bash -l inside a login shell where the .bash_profile is not idempotent.


    I believe the inverse will also cause problems though because I was still getting issues around it before I changed it, here's a bit of history on the issue:

    One problem that will probably occur is people will lose their aliases because they set them up in .bash_profile which is run on launch by the shell in external terminals, but they would be lost if VS Code launches the login shell and the terminal launches a non-login shell.

  3. added
    under-discussion
    macos
    terminal
    and removed
    bug
    on May 23, 2018
  4. jasper-zanjani commented on Jul 4, 2019

    @jasper-zanjani

    I was just about to file a bug report. Because it is impossible to remove that option from the default behavior, and it is not possible to specify an empty string in settings.json, the user has to manually configure a workable option (e.g. -Interactive for Powershell Core) which will override the default -l.

    But the bug does break the usability of PowerShell Core in the integrated terminal out of the box, an odd decision for Microsoft devs to make.

  5. Tyriar commented on Jul 4, 2019

    @Tyriar
    Contributor

    The solution for this is captured in #70248 (windows deferred to #47816)

  6. locked and limited conversation to collaborators on Aug 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

macosterminalunder-discussion

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions