Skip to content

Login switch not used #2384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bgelens opened this issue Dec 20, 2019 · 6 comments · Fixed by #2400
Closed

Login switch not used #2384

bgelens opened this issue Dec 20, 2019 · 6 comments · Fixed by #2400
Labels
Area-Startup Issue-Enhancement A feature request (enhancement).

Comments

@bgelens
Copy link

bgelens commented Dec 20, 2019

System Details

System Details Output

### VSCode version: 1.41.1 26076a4de974ead31f97692a0d32f90d735645c0 x64

### VSCode extensions:
2gua.rainbow-brackets@0.0.6
adamhartford.vscode-base64@0.1.0
andreaslenzen.vbscript-language-server-client@1.0.3
Azurite.azurite@3.3.0
ban.spellright@3.0.48
DavidAnson.vscode-markdownlint@0.33.0
donjayamanne.githistory@0.4.11
eamodio.gitlens@10.2.0
EditorConfig.EditorConfig@0.14.4
Equinusocio.vsc-material-theme@30.0.0
eriklynd.json-tools@1.0.2
GrapeCity.gc-excelviewer@2.1.32
mauve.terraform@1.4.0
ms-azure-devops.azure-pipelines@1.157.4
ms-azuretools.vscode-azureappservice@0.16.2
ms-azuretools.vscode-azurefunctions@0.20.1
ms-azuretools.vscode-docker@0.9.0
ms-kubernetes-tools.vscode-aks-tools@0.0.4
ms-kubernetes-tools.vscode-kubernetes-tools@1.0.9
ms-mssql.mssql@1.8.0
ms-python.python@2019.11.50794
ms-vscode.azure-account@0.8.7
ms-vscode.azurecli@0.4.6
ms-vscode.cpptools@0.26.2
ms-vscode.csharp@1.21.9
ms-vscode.Go@0.11.9
ms-vscode.powershell@2019.12.0
ms-vscode.powershell-preview@2019.12.0
msazurermtools.azurerm-vscode-tools@0.8.3
PKief.material-icon-theme@3.9.2
redhat.vscode-xml@0.10.1
redhat.vscode-yaml@0.6.1
Shan.code-settings-sync@3.4.3
tht13.html-preview-vscode@0.2.5
twxs.cmake@0.0.17
Tyriar.shell-launcher@0.4.0
vitaliymaz.vscode-svg-previewer@0.5.1
wayou.vscode-todo-highlight@1.0.4
yzane.markdown-pdf@1.4.1


### PSES version: 2.0.0.0

### PowerShell version:

Name                           Value
----                           -----
PSVersion                      7.0.0-rc.1
PSEdition                      Core
GitCommitId                    7.0.0-rc.1
OS                             Darwin 19.2.0 Darwin Kernel Version 19.2.0: Sat Nov  9 03:47:04 PST 2019; root:xnu-6153.61.1~20/RELEASE_X86_64
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Issue Description

Depending if I open VS Code from a terminal code . or directly I have different paths in my $env:PATH variable.

From terminal:

/usr/local/microsoft/powershell/7-preview
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/share/dotnet
~/.dotnet/tools

Directly:

/usr/local/microsoft/powershell/7-preview
/usr/bin
/bin
/usr/sbin
/sbin

The difference here is that my terminal session is using -l when starting pwsh (it's my login shell)

Expected Behaviour

I would expect that Integrated Console would use -l when available or have an overwrite similar to:

"terminal.integrated.shellArgs.osx": [
    "-l"
 ],
@ghost ghost added the Needs: Triage Maintainer attention needed! label Dec 20, 2019
@rjmholt
Copy link
Contributor

rjmholt commented Jan 2, 2020

@bgelens could you be more specific about what you have that works today and what you're expecting the integrated console to do?

The difference here is that my terminal session is using -l when starting pwsh (it's my login shell)

Do you mean you've set pwsh to be your login shell in System Preferences and when you open an ordinary terminal it starts as a login shell, or that you've configured your terminal to start pwsh with pwsh -l manually, or that you have pwsh in the VSCode console (not the Integrated Console) starting with pwsh -l with some manual configuration? Or some combination of these?

I would expect that Integrated Console would use -l when available

Do you mean that you want the Integrated Console to always start as a login shell by default if possible?

Rather than allowing setting arguments like the suggestion above (which opens the door on a few issues, one being injection attacks), perhaps something like "powershell.startAsLogin": true?

When you set a login shell in *nix, it actually never passes -l as an argument; it prepends the process' name with a - (and PowerShell performs that detection). Since we start PowerShell using a VSCode API for terminal creation, I don't think we can do that. But we can probably add the -Login switch easily enough.

@rjmholt
Copy link
Contributor

rjmholt commented Jan 2, 2020

Looking at this more closely, there's no way for us to determine whether the login switch is available with a given PowerShell other than by starting it and checking the exit code, which is slow.

It's simple to implement it to just add the -Login switch at the user's own risk, but to make it magically know if it can use the switch is quite costly.

@rjmholt rjmholt added Area-Startup Issue-Enhancement A feature request (enhancement). and removed Needs: Triage Maintainer attention needed! labels Jan 2, 2020
@rjmholt rjmholt mentioned this issue Jan 2, 2020
4 tasks
@ghost ghost added the Status: In PR label Jan 2, 2020
@bgelens
Copy link
Author

bgelens commented Jan 3, 2020

Do you mean you've set pwsh to be your login shell in System Preferences and when you open an ordinary terminal it starts as a login shell

Yes , configured via chsh

or that you've configured your terminal to start pwsh with pwsh -l manually

No

or that you have pwsh in the VSCode console (not the Integrated Console) starting with pwsh -l with some manual configuration

Yes but just recently as I sometimes run into issues where I restart vs code using command palette where the environmental variables where not the same between sessions. I added this argument to the configuration to try and fix the IC as I thought it would inherit from the vs code default shell but I know now this is not the case.

This is actually my issue, I have a lot of things installed using brew, I normally start vs code from a terminal and vs code inherits the environmental variables so everything works as expected. Starting vs code directly or using restart command breaks my flow :)

Do you mean that you want the Integrated Console to always start as a login shell by default if possible?

Yes or configurable using an option is fine as well for me.

I'm not sure why the possibility for injection is a red flag considering the normal vs-code terminal already allows this. But as said, I don't mind an additional option so I can configure it myself.

Thanks for the additional info on how startup shell actually works :) I had no idea.

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Jan 3, 2020
@rjmholt
Copy link
Contributor

rjmholt commented Jan 3, 2020

This is actually my issue, I have a lot of things installed using brew, I normally start vs code from a terminal and vs code inherits the environmental variables so everything works as expected. Starting vs code directly or using restart command breaks my flow :)

Ah! Do you know where you set those env vars? Running pwsh as a login shell will run ~/.profile even if ~/.bash_profile is defined, since it tries to emulate POSIX sh for universality. Just want to let you know in case running PowerShell as a login shell won't end up solving the problem.

Makes me think we should work out some way to "source" env vars from bash/sh into the enclosing PowerShell process.

I'm not sure why the possibility for injection is a red flag considering the normal vs-code terminal already allows this

It would be alright as a user level setting I think, but not a workspace one -- that distinction is something VSCode has identified in their own configurations without huge explanation, but we usually try to follow it. That might be worth investigating more actually. It would probably work best as an extra configuration for an "addtional PowerShell exe", which we could then plumb through.

@SydneyhSmith SydneyhSmith removed the Needs: Maintainer Attention Maintainer attention needed! label Jan 6, 2020
@TylerLeonhardt
Copy link
Member

I'm curious @bgelens, does the non-Integrated Console have the environment variables you expect? If that doesn't give you the typical environment variables you expect from a login shell, I don't know if we want to change the behavior of the Integrated Console.

@bgelens
Copy link
Author

bgelens commented Jan 8, 2020

@rjmholt I don't have a .profile 🤷‍♂

@TylerLeonhardt

  • When I start vs code from my login shell (pwsh-preview) everything is fine (code .)
    both IC and non IC
  • When I start vs code as application directly (spotlight search, application folder) non-integrated is fine as it has the extra -l argument defined
    "terminal.integrated.shellArgs.osx": [
      "-l"
    ]
    
    IC is not fine (nothing from brew is available)

It's more an inconvenience as a blocker for me as normally I launch everything from iterm2.

Maybe nice for troubleshooting.

printenv from ic using shortcut startup:

LOGNAME=bengelens
PSModulePath=/Users/bengelens/.local/share/powershell/Modules:/usr/local/share/powershell/Modules:/usr/local/microsoft/powershell/7-preview/Modules:/Users/bengelens/.vscode/extensions/ms-vscode.powershell-preview-2019.12.0/modules
USER=bengelens
HOME=/Users/bengelens
XPC_FLAGS=0x0
TMPDIR=/var/folders/n8/lm_9wknj36d18770pg1k0vsw0000gn/T/
XPC_SERVICE_NAME=com.microsoft.VSCode.7436
LANG=en_US.UTF-8
TERM=xterm-256color
__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0
COLORTERM=truecolor
PATH=/usr/local/microsoft/powershell/7-preview:/usr/bin:/bin:/usr/sbin:/sbin
TERM_PROGRAM_VERSION=1.41.1
SHELL=/usr/local/bin/pwsh-preview
TERM_PROGRAM=vscode
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.0lS7fxBv2c/Listeners
PWD=/Users/bengelens

printenv from ic started from terminal (code .)

__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0
SHELL=/usr/local/bin/pwsh-preview
LOGNAME=bengelens
LC_CTYPE=UTF-8
_=/Applications/Visual Studio Code.app/Contents/MacOS/Electron
SHLVL=1
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.0lS7fxBv2c/Listeners
TERM_SESSION_ID=w0t0p0:4C671856-ED22-4AD6-A0D9-EBA306C7E7E1
ITERM_SESSION_ID=w0t0p0:4C671856-ED22-4AD6-A0D9-EBA306C7E7E1
LC_TERMINAL_VERSION=3.3.7
TERM_PROGRAM_VERSION=1.41.1
COLORFGBG=7;0
XPC_FLAGS=0x0
COLORTERM=truecolor
XPC_SERVICE_NAME=0
TMPDIR=/var/folders/n8/lm_9wknj36d18770pg1k0vsw0000gn/T/
PWD=/Users/bengelens
LC_TERMINAL=iTerm2
USER=bengelens
HOME=/Users/bengelens
PATH=/usr/local/microsoft/powershell/7-preview:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:~/.dotnet/tools
TERM=xterm-256color
APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL=true
PSModulePath=/Users/bengelens/.local/share/powershell/Modules:/usr/local/share/powershell/Modules:/usr/local/microsoft/powershell/7-preview/Modules:/Users/bengelens/.vscode/extensions/ms-vscode.powershell-preview-2019.12.0/modules
LANG=en_US.UTF-8
ITERM_PROFILE=Default
TERM_PROGRAM=vscode

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Jan 8, 2020
@SydneyhSmith SydneyhSmith removed the Needs: Maintainer Attention Maintainer attention needed! label Jan 9, 2020
@ghost ghost added Status: Fixed and removed Status: In PR labels Jan 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Startup Issue-Enhancement A feature request (enhancement).
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants