ensure running powershell within PowerShell starts instance of currently running PowerShell#4481
Merged
daxian-dbw merged 2 commits intoPowerShell:masterfrom Aug 4, 2017
Merged
Conversation
…ently running PowerShell modify PATH env var at startup so that $PSHOME is in front
daxian-dbw
requested changes
Aug 3, 2017
| if (!Platform.IsWindows) | ||
| { | ||
| pathSeparator = ":"; | ||
| } |
Member
There was a problem hiding this comment.
You can use Path.PathSeparator.
| pathSeparator = ":"; | ||
| } | ||
| string pshome = Utils.DefaultPowerShellAppBase; | ||
| path.Replace(pathSeparator + pshome, ""); |
Member
Author
There was a problem hiding this comment.
I thought that the PWD got appended to the end of PATH so I didn't want it on both ends, looks like that isn't the case. I'll remove.
| } | ||
| string pshome = Utils.DefaultPowerShellAppBase; | ||
| path.Replace(pathSeparator + pshome, ""); | ||
| path.Insert(0, pshome + pathSeparator); |
Member
There was a problem hiding this comment.
We should check if the first path in $env:PATH is pshome, and only insert if it's not. Otherwise, the nested powershell instance will have 2 pshome paths in $env:PATH
iSazonov
reviewed
Aug 6, 2017
| } | ||
| #endif | ||
|
|
||
| // put PSHOME in front of PATH so that calling `powershell` within `powershell` always starts the same running version |
Collaborator
There was a problem hiding this comment.
- Is this right for other applications?
- I would prefer more deterministic
[System.Diagnostics.Process]::GetCurrentProcess().MainModule.FileName. (Related Improve experience for side-by-side versions of PowerShell #4199 . What aboutStart-PowerShellcmdlet?)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
modify PATH env var at startup so that $PSHOME is in front
Fix #4194